【发布时间】:2018-04-13 13:21:46
【问题描述】:
我想知道如何定位 Angular Material Table 内的偶数/奇数行,以便我可以将偶数/奇数行设置为不同的背景颜色。
我设置了我的ClaimFileHistoryDataSource 课程:
claimClientInformation: ClaimFileHistory[];
dataSource : ClaimFileHistoryDataSource;
displayedColumns = ['TypeImg', 'Description', 'Agent'];
export class ClaimFileHistoryDataSource extends DataSource<ClaimFileHistory> {
constructor(private _claimFileHistory: ClaimFileHistory[]) {
super();
}
connect(): Observable<ClaimFileHistory[]> {
return Observable.of(this._claimFileHistory);
}
disconnect() {}
}
在NgInit 上,我调用我的服务去获取我需要的数据并填充DataSource:
this._claimFileHistoryService.getClaimFileHistoryById().subscribe(response => {
this.claimClientInformation = response;
this.dataSource = new ClaimFileHistoryDataSource(this.claimClientInformation);
});
这很好,数据会按原样返回。
在 HTML 中,Mat-Table 如下所示:
<mat-table #table [dataSource]="dataSource">
<ng-container matColumnDef="TypeImg">
<mat-cell *matCellDef="let row"><img [src]='row.TypeImg' height="40px"></mat-cell>
</ng-container>
<ng-container matColumnDef="Description">
<mat-cell *matCellDef="let row">
<div>
<span class="d-block">{{row.Description}}</span>
<span class="d-block">{{row.Date}}</span>
</div>
</mat-cell>
</ng-container>
<ng-container matColumnDef="Agent">
<mat-cell *matCellDef="let row"> {{row.Agent}} </mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
</mat-table>
我再次想知道如何获取表格的奇数/偶数行并将它们设置为不同的行背景颜色?
【问题讨论】:
标签: html css angular angular-material2