I am wondering how I aim even / odd lines inside Angular Material Table
so that I can set even / odd lines of a different background color.
I am setting up a class 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() {}
}
As NgInit
I call to their service to go and get me the necessary data and to fill in DataSource
:
this._claimFileHistoryService.getClaimFileHistoryById().subscribe(response => {
this.claimClientInformation = response;
this.dataSource = new ClaimFileHistoryDataSource(this.claimClientInformation);
});
This is normal and the data is returned properly.
In HTML Mat-Table
it looks like this:
<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>
Again I wondered, how do I deal with getting the rows of the Odd / Even table and setting them to a different row background color?
source
share