首页 > 解决方案 > 如何使用属性根据数据更改剑道网格行颜色背景

问题描述

在我的剑道网格中,我可以使用以下方法更改单元格的颜色,但不能更改行的颜色。

对于值为 的所有事件,我得到绿色rainy,但红色仅适用于单元格而不适用于行。我怎么能得到那个?

$("#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 # },  #"
    },
  }
}

标签: jquerykendo-ui

解决方案


dataBound您可以在活动中实现这一点。

        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 示例: 有条件地更改 Kendo Grid Row 颜色


推荐阅读