我希望使用带有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()的预期用途中遗漏了什么,有没有人看到一个明显的问题?
问题是.Ajax()和.RowAction()是互斥的
http://www.kendoui.com/forums/kendo-ui-web/grid/ajax-binding-and-rowaction-conflict-.aspx
只是因为我今天遇到了这个问题,为了节省时间,这里根据卡住的解释为我提供了简短的答案
将其添加到网格中
.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');
}
})
}