【问题标题】:Changing row color in Kendo MVC grid, using RowAction使用 RowAction 更改 Kendo MVC 网格中的行颜色
【发布时间】:2014-01-17 16:47:44
【问题描述】:

我希望使用带有 lambda 的 RowAction 来设置 Grid 中几行数据的背景颜色。

<%: Html.Kendo().Grid<HomeController.SuccessfulBuildsByDevice>()
                        .Name("Grid")
                        .Columns(columns =>
                        {                   
                            columns.Bound(p => p.A);
                            columns.Bound(p => p.B);
                        })
                        .Scrollable()
                        .Sortable()
                        .Filterable()
                        .RowAction(row =>
                            {
                                if(row.DataItem.A > row.DataItem.B)
                                    row.HtmlAttributes["style"] = "background:red";
                            })
                        .HtmlAttributes(new { style = "height:500" })  
                        .DataSource(dataSource => dataSource
                            .Ajax()
                            .Read(read => read.Action("_GetData", "Home"))
                            .ServerOperation(false)
                        )
                    %>

但是,当我使用上述方法时,似乎没有调用 RowAction()。我尝试设置断点等。我是否在 RowAction() 的预期用途中遗漏了某些内容,有人看到明显的问题吗?

【问题讨论】:

    标签: asp.net-mvc kendo-ui telerik


    【解决方案1】:

    【讨论】:

    • 这个答案对我有用。我没有使用 .Ajax()。
    • 数小时的研究和挖掘终于找到了答案!
    【解决方案2】:

    只是因为我今天来到了这个问题,为了节省时间,根据卡住的解释对我有用的简短答案

    将此添加到网格中

    .Events(e => e.DataBound("onDataBound"))
    

    在网格上方添加这个 javascript

    function onDataBound() {
        // get the grid
        var grid = this;
        // iterate through each row
        grid.tbody.find('>tr').each(function () {
            // get the row item
            var dataItem = grid.dataItem(this);
            // check for the condition
            if (dataItem.IsArchived) {
                // add the formatting if condition is met
                $(this).addClass('bgRed');
            }
        })
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-26
      相关资源
      最近更新 更多