Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change color of row based on particular column condition in kendo grid for angular

I want to apply red color to row whose completedIn hours column value is greater than 24. how can i do it. please help i am new to angular.

<kendo-grid [kendoGridBinding]="gridData">
    <kendo-grid-column field="RequestNumber" title="Request No."  
width="110" >
    </kendo-grid-column>
<kendo-grid-column field="RequestNumber" title="Request No."  width="110" >
    </kendo-grid-column>
<kendo-grid-column field="Name" title="Name."  width="110" >
    </kendo-grid-column>
<kendo-grid-column field="CompletedIn" title="CompletedIn"  width="110" >
    </kendo-grid-column>
 </kendo-grid>
like image 605
user9287106 Avatar asked Feb 06 '19 12:02

user9287106


1 Answers

First: you have to add [rowClass] to your grid

<kend-grid [rowClass]="rowCallback">
</kendo-grid>

then you need to add the function inside the component and return the needed class

public rowCallback(context: RowClassArgs) {
  if (context.dataItem.someProperty) {   // change this condition as you need
    return {
      passive: true
    };
  }
}  

and last you need to have a CSS class with the name you returned,(in this case passive but of course you can change it as you want)

@Component({
  selector: "your-component",
  templateUrl: "./your.component.html",
  encapsulation: ViewEncapsulation.None,
  styles: [
    `
     .k-grid tr.passive {
        background-color: lightgray;
      }

    `
  ]
})

it is very important to use encapsulation: ViewEncapsulation.None and name the class with the prefix .k-grid tr otherwise you will not get the needed result

like image 170
Hakan Fıstık Avatar answered Sep 21 '22 05:09

Hakan Fıstık