我需要根据特定条件更改剑道 ui 网格的行颜色。我正在使用带有 MVC 的服务器端绑定。我的代码如下,
var grid = Html.Kendo().Grid<AllocateCOESGridViewModel>();
grid.Name("AllocateResultGrid")
.RowAction(row =>
{
if (row.DataItem.COESNo == 13054915)
{
row.HtmlAttributes["style"] = "background:blue";
}
else
{
row.HtmlAttributes["style"] = "background:red";
}
})
.Columns(columns =>
{
columns.Bound(s => s.COESNo).Title(@Allocate.COESGridHeading);
columns.Bound(s => s.Street).Title(@Allocate.StreetGridHeading);
columns.Bound(s => s.Suburb).Title(@Allocate.SuburbGridHeading);
columns.Bound(s => s.Postcode).Title(@Allocate.PostcodeGridHeading);
columns.Bound(s => s.InspectorName).Title(@Allocate.InspectorGridHeading);
columns.Bound(s => s.COESNo).Title(@Allocate.AllocateGridHeading + "<input type ='checkbox' id ='SelectAll' />").ClientTemplate("<input type ='checkbox' data-id='#= COESNo #' class='allocate' />").Sortable(false);
});
网格有效但根本没有行颜色?没有蓝色或红色..我只是得到标准的白色和灰色..有什么想法吗?
谢谢
这就是我让它工作的方式,只是想知道是否还有其他选择,因为遍历网格似乎不是一个好主意......特别是如果网格很长
var grid = $("#AllocateResultGrid").data("kendoGrid");
grid.bind("dataBound", updateGridRows);
updateGridRows: function()
{
dataView = this.dataSource.view();
for (var i = 0; i < dataView.length; i++)
{
if (dataView[i].Selected == false)
{
var uid = dataView[i].uid;
$("#AllocateResultGrid tbody").find("tr[data-uid=" + uid + "]").addClass("customClass");
}
}
}
我在样式表中添加了 customClass