使用RowAction更改Kendo MVC网格中的行颜色

问题描述 投票:4回答:2

我希望使用带有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
2个回答
8
投票

0
投票

只是因为我今天遇到了这个问题,为了节省时间,这里根据卡住的解释为我提供了简短的答案

将其添加到网格中

.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');
        }
    })
}
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.