Search code examples
angulartypescriptngx-datatable

Set row color to specific rows


I am working on Angular4 project and am using ngx-datatable so .html file looks like

<ngx-datatable> <ngx-datatable-column> <ng-template> ... {{row.value}}

What I want to achieve is to check for value, whether with *ngIf or inside typescript for value, and if value > 100 set ROW background to red, else it should be white as it is.

How to achieve that? Thanks for help


Solution

  • Usually you can exchange CSS classes conditionally as follows:

    <ng-template [ngClass]="{red: row.value >= 100, white: row.value < 100}">
    

    Of course you have to define the CSS-styles behind both classes red and white in your CSS-file.