【问题标题】:How to change Kendo grid row color background based on the data using attribute如何使用属性根据数据更改剑道网格行颜色背景
【发布时间】:2019-06-25 10:12:26
【问题描述】:

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

对于值为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 # },  #"
    },
  }
}

【问题讨论】:

    标签: jquery kendo-ui


    【解决方案1】:

    您可以在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";
                    }
                })
            }
    

    道场示例: Change Kendo Grid Row color conditionally

    【讨论】:

    • 谢谢,但我更改了一些代码,它在我输入的条件部分有效 $('tr[data-uid="' + dataItem.uid + '"] ').css( "background-color", "green");我会选择你的作为答案,因为帮助我找出了问题
    猜你喜欢
    • 1970-01-01
    • 2012-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-19
    • 2013-08-04
    相关资源
    最近更新 更多