如何根据列单元格值更改角度材料的行颜色。我的html中有这个
<mat-table [dataSource]="dataSource" class="mat-elevation-z2" style="margin-bottom: 10px;" matSort>
<ng-container matColumnDef="DateAdded">
<mat-header-cell *matHeaderCellDef mat-sort-header> Submission Time </mat-header-cell>
<mat-cell *matCellDef="let row"> {{row.DateAdded | date: 'medium'}} </mat-cell>
</ng-container>
<ng-container matColumnDef="StartDate">
<mat-header-cell *matHeaderCellDef mat-sort-header> Start Date </mat-header-cell>
<mat-cell *matCellDef="let row"> {{row.StartDate | date}} </mat-cell>
</ng-container>
<ng-container matColumnDef="EndDate">
<mat-header-cell *matHeaderCellDef mat-sort-header> End Date </mat-header-cell>
<mat-cell *matCellDef="let row"> {{row.EndDate | date}} </mat-cell>
</ng-container>
<ng-container matColumnDef="IsGranted">
<mat-header-cell *matHeaderCellDef mat-sort-header> Granted </mat-header-cell>
<mat-cell *matCellDef="let row" [ngClass]="row.IsGranted ? 'make-green' : ''"> {{row.IsGranted}} </mat-cell>
</ng-container>
<ng-container matColumnDef="Remarks">
<mat-header-cell *matHeaderCellDef> Remarks </mat-header-cell>
<mat-cell *matCellDef="let row" [style.color]="row.color">
<button class="btn btn-dark btn-sm" (click)="viewRemarks(row.Remarks)">Select</button>
</mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns" [ngClass]="{'make-green': row.IsGranted==true}"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;">
</mat-row>
</mat-table>
<mat-paginator [pageSizeOptions]="[5, 10, 25, 100]"></mat-paginator>
在我的CSS中就是这样。
.make-gold {
background-color: gold
}
我需要更改整个行的背景色。不只是细胞。谢谢。
答案 0 :(得分:3)
我假设您要在var md = require('markdown-it')({
html: true
});
值为true时应用make-gold
类。如果是这种情况,请尝试以下操作:
IsGranted
另请参见stackblitz demo。
还有一种简写语法:
<mat-row *matRowDef="let row; columns: displayedColumns;" [ngClass]="{'make-gold': row.IsGranted }">