How to change Kendo grid row color background based on the data using attribute

Viewed 1827

In my kendo grid I can change the color of the cell but not the row with the following approach.

I get a green color for all those events whose value is rainy, but the red color only applies to the cell but not the row. How can I get that?

$("#grid").kendoGrid({
  dataSource: myDB,
  height: 550,
  {
    field: "User",
    title: "User",
    width: "50px",
  },
  {
    field: "WindSpeed",
    title: "Wind Speed",
    width: "40px"
  },
  {
    field: "EventName",
    title: "Event Type",
    width: "50px",
    attributes: {
      " class": "# if(data.EventName === 'rainy') { # green # } else { # white # },  #"
    },
  }
}
1 Answers

You can achieve this in the dataBound event.

        var grid = $("#grid").data("kendoGrid");
        grid.bind("dataBound", grid_dataBound);
        grid.dataSource.fetch();

        function grid_dataBound(e) {
            var items = e.sender.items();
            items.each(function (index) {
                var dataItem = grid.dataItem(this);
                if (dataItem.age > 32) {
                    this.className += " customClass1";
                }
                else {
                    this.className += " customClass2";
                }
            })
        }

Dojo Example: Change Kendo Grid Row color conditionally

Related