如何将某些样式应用于角形材料表中的表行 [英] How to apply some style to the table row in angular material table
本文介绍了如何将某些样式应用于角形材料表中的表行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这张桌子:
<div class="table-container">
<table mat-table [dataSource]="dataSource">
<mat-divider></mat-divider>
<!-- title column -->
<ng-container matColumnDef="title">
<th mat-header-cell *matHeaderCellDef> {{ 'NOTIFYCATION.NOTIFY_TITLE' | translate }} </th>
<td mat-cell *matCellDef="let element"> {{element.title}} </td>
</ng-container>
<!-- code column -->
<ng-container matColumnDef="description">
<th mat-header-cell *matHeaderCellDef> {{ 'NOTIFYCATION.DESCRIPTION' | translate }} </th>
<td mat-cell *matCellDef="let element"> {{element.description}} </td>
</ng-container>
<!-- code column -->
<ng-container matColumnDef="receiverDisplayName">
<th mat-header-cell *matHeaderCellDef> {{ 'NOTIFYCATION.RECEIVER_DISPLAY_NAME'| translate }} </th>
<td mat-cell *matCellDef="let element"> {{element.receiverDisplayName}} </td>
</ng-container>
<!-- code column -->
<ng-container matColumnDef="type">
<th mat-header-cell *matHeaderCellDef> {{ 'NOTIFYCATION.TYPE'| translate }} </th>
<td mat-cell *matCellDef="let element"> {{element.type}} </td>
</ng-container>
<ng-container matColumnDef="createdOnUtc">
<th mat-header-cell *matHeaderCellDef> {{ 'USER_SUBSCRIBE.createdOnUtc' | translate }} </th>
<td mat-cell *matCellDef="let element">
<span *ngIf="lang=='fa'">{{ element.createdOnUtc | jalali }}</span>
<span *ngIf="lang!='fa'"> {{element.createdOnUtc | date: 'dd/MM/yyyy hh:mm'}} </span>
</td>
</ng-container>
<!-- actions -->
<ng-container style="color: red;" matColumnDef="actions">
<th mat-header-cell *matHeaderCellDef>
{{ 'GENERAL.ACTIONS' | translate }}
</th>
<td mat-cell *matCellDef="let row; let i=index;">
<a mat-icon-button [matTooltip]="'TOOLTIP.DETAIL' | translate">
<mat-icon aria-label="Show" (click)="showDetail(row)" class="ic-defualt">remove_red_eye
</mat-icon>
</a>
<button mat-icon-button [matTooltip]="'TOOLTIP.DELETE' | translate" color="accent" uaccess
[permission]="':GiftCode:Delete'" (click)="delete(row.id)">
<mat-icon aria-label="Delete">delete</mat-icon>
</button>
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr *matCellDef="let row; let element" [ngClass]="{'highlight': element.isSeen ==='true'}">
{{element.bestRider}} </tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
<mat-progress-bar *ngIf="dataSource.loading$ | async" mode="indeterminate"></mat-progress-bar>
<mat-paginator [length]="dataSource.length$ | async" [pageSize]="pageSize" [pageSizeOptions]="pageSizeOptions"
showFirstLastButtons></mat-paginator>
</div>
当 isSeen = false
时,我需要将 tr
的颜色更改为 red
.
I need to change color of tr
to red
when isSeen=false
.
我尝试:
<tr *matCellDef="let row; let element" [ngClass]="{'highlight': element.isSeen ==='true'}"></tr>
CSS:
.highlight{
color: white;
background: #673AB7;
}
但不起作用.
出什么问题了?我该如何解决这个问题?
Whats the problem? how can I solve this problem?
推荐答案
您的最后一个mat-header-row缺少一些代码,请使用 row.isSeen
(其中包含当前的迭代行).
Your last mat-header-row has missing some code and use row.isSeen
which contains the current iteration row in it.
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;" [ngClass]="{'highlight': row.isSeen }"></tr>
用上面的代码替换最后一个mat-header-row,将起作用:
Replace last mat-header-row with above code and will work:
这是 在线演示
这篇关于如何将某些样式应用于角形材料表中的表行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文