【发布时间】:2014-02-13 17:00:44
【问题描述】:
我有一个显示警报列表的 ajax 绑定网格。根据行对象中的某些条件,我需要更改行的颜色。
这在以前有效,当我的网格被服务器绑定时(我知道这是它应该工作的方式),但是由于需要使用 ajax 更新网格。
这是我的网格,以及在服务器绑定时使用的网格(注意我已更改为 .Ajax():
@(Html.Kendo().Grid(Model.Alarms)
.Name("grid")
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(false)
.Model(m => m.Id(s => s.AlarmComment))
.Read(read => read.Action("Alarms_Read", "Alarms", new { id = Model.ViewUnitContract.Id }).Type(HttpVerbs.Get))
.AutoSync(true)
.ServerOperation(true)
)
.RowAction(row =>
{
if (row.DataItem.DateOff == null && row.DataItem.DateAck == null)
{
row.HtmlAttributes["style"] = "backgrcolor:red";
}
if (row.DataItem.DateOff != null && row.DataItem.DateAck == null)
{
row.HtmlAttributes["style"] = "color: green";
}
if (row.DataItem.DateOff == null && row.DataItem.DateAck != null)
{
row.HtmlAttributes["style"] = "color: blue";
}
})
.Columns(col =>
{
col.Bound(p => p.DateOn).Format("{0:u}").Title("Date");
col.Bound(p => p.Priority).Width(50);
col.Bound(p => p.ExtendedProperty2).Width(100).Title("Action");
col.Bound(p => p.AlarmTag).Title("Name");
col.Bound(p => p.AlarmComment).Title("Comment");
col.Bound(p => p.ExtendedProperty1).Title("AlarmID");
col.Bound(x => x.DateOff).Title("Value");
})
.HtmlAttributes(new {style = "height:430px;"})
.Events(e => e.DataBound("setColors"))
)
现在,这就是我在脚本中所做的:
function setColors() {
var grid = $("#grid").data("kendoGrid");
var data = grid.dataSource.data();
$.each(data, function(i, row) {
if (row.DateOff != null && row.DateAck == null) {
// Add color to that rows text
}
});
}
我终其一生都无法弄清楚如何更改该行文本的颜色。有什么建议吗?
【问题讨论】:
-
我在哪里可以获得可用颜色的列表
-
不确定我理解您所说的“颜色可用”是什么意思。它们只是常规颜色,在 CSS 或十六进制中使用。
-
我的意思是我在哪里可以获得我可以在那里使用的所有颜色的列表,我知道我可以使用十六进制值,并且我找到了一个包含颜色列表的站点,例如“LightGreen”、“ DarkRed'等
标签: javascript jquery kendo-ui kendo-grid