I just started with a basic approach so I want to highlight row color conditionally its not throwing any error but does not apply the background-color to the row. I have 5 rows that have riskINdex
H
, Any idea what is implemented wrong in below code?
app.component.html
<div>
<mat-table>
<ng-container matColumnDef="eventType">
<mat-header-cell *matHeaderCellDef> Event Type </mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.eventType}} </mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;" (click)="selectedRow(row)" [ngClass]="{ 'high': row.riskIndex === 'High'}"></mat-row>
</mat-table>
</div>
component.css
.high {
background-color: red;
}
Suppose, You want to highlight mat-row
by some model property. lets say highlight when status == Approved.
<tr mat-row *matRowDef="let row; columns: displayedColumns;let entry"[ngClass]="{ 'highlight': entry.status == 'Approved' }"></tr>
In the above line of code,
highlight
is css
class defined in .css file.
.highlight{
background: #42A948; /* green */
}
The above .css file included in component as following.
@Component({
styleUrls: ['./expense.component.css'],
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With