Asp.net mvc 如何在kendo ui mvc网格中基于条件格式化行
我正在asp.NETMVC上工作。我试图在剑道mvc ui网格中显示消息列表。 我编写了如下代码:Asp.net mvc 如何在kendo ui mvc网格中基于条件格式化行,asp.net-mvc,asp.net-mvc-3,kendo-ui,Asp.net Mvc,Asp.net Mvc 3,Kendo Ui,我正在asp.NETMVC上工作。我试图在剑道mvc ui网格中显示消息列表。 我编写了如下代码: Html.Kendo().Grid((List<messages>)ViewBag.Messages)) .Name("grdIndox") .Sortable(m => m.Enabled(true).SortMode(GridSortMode.MultipleColumn)) .H
Html.Kendo().Grid((List<messages>)ViewBag.Messages))
.Name("grdIndox")
.Sortable(m => m.Enabled(true).SortMode(GridSortMode.MultipleColumn))
.HtmlAttributes(new { style = "" })
.Columns(
col =>
{
col.Bound(o => o.RecNo).HtmlAttributes(new { style = "display:none" }).Title("").HeaderHtmlAttributes(new { style = "display:none" });
col.Bound(o => o.NoteDate).Title("Date").Format("{0:MMM d, yyyy}");
col.Bound(o => o.PatName).Title("Patient");
col.Bound(o => o.NoteType).Title("Type");
col.Bound(o => o.Subject);
}
)
.Pageable()
.Selectable(sel => sel.Mode(GridSelectionMode.Single).Type(GridSelectionType.Row))
.DataSource(
ds => ds.Ajax().ServerOperation(false).Model(m => m.Id(modelid => modelid.RecNo))
.PageSize(10)
//.Read(read => read.Action("Messages_Read", "Msg"))
)
.Events(ev => ev.Change("onSelectingGirdRow"))
)
Html.Kendo().Grid((列表)ViewBag.Messages))
.名称(“grdIndox”)
.Sortable(m=>m.Enabled(true).SortMode(GridSortMode.MultipleColumn))
.HtmlAttributes(新{style=”“})
.栏目(
列=>
{
col.Bound(o=>o.RecNo).HtmlAttributes(新的{style=“display:none”}).Title(“”).HeaderHtmlAttributes(新的{style=“display:none”});
col.Bound(o=>o.NoteDate).Title(“Date”).Format(“{0:mmmd,yyyy}”);
col.Bound(o=>o.PatName).Title(“患者”);
col.Bound(o=>o.NoteType).Title(“Type”);
col.Bound(o=>o.Subject);
}
)
.Pageable()
.可选(sel=>sel.Mode(GridSelectionMode.Single).类型(GridSelectionType.Row))
.数据源(
ds=>ds.Ajax().ServerOperation(false).Model(m=>m.Id(modelid=>modelid.RecNo))
.页面大小(10)
//.Read(Read=>Read.Action(“Messages\u Read”,“Msg”))
)
.Events(ev=>ev.Change(“onSelectingGirdRow”))
)
表中的字段类似于IsRead布尔类型。因此,如果消息是未读消息,那么我需要用粗体字体格式化该记录。我使用了clientTemplates,但使用它我只能格式化特定的单元格,我想格式化整行。请指导我。您可以使用数据绑定事件更改行
dataBound: function ()
{
$('td').each(function(){
if(some condition...)
{
$(this).addClass('someBoldClass')}
}
})
}
正如Sanja所建议的,您可以使用dataBound事件,但最好在tr元素(行)之间循环。另外,我假设您需要相关的属性来检查指示消息是否已读取的属性 e、 g
还有另一种方法,叫做
请注意,行操作仅适用于在服务器端渲染的行。因此,在您的情况下,您可以使用RowAction作为DataBound的替代方法,它不应该像$(this).find(“tr”).each(function()…?按照您编写它的方式,它将在页面上的所有TR中循环。没错,我更新了我的帖子,现在它只在Grid table元素的直接子行中循环。如果您使用服务器数据绑定,ala数据源(ds=>ds.server(),您不能使用grid.dataItem访问javascript中的基础数据项(此)?
dataBound: function ()
{
var grid = this;
grid.tbody.find('>tr').each(function(){
var dataItem = grid.dataItem(this);
if(!dataItem.IsMessageRead)
{
$(this).addClass('someBoldClass');
}
})
}
.RowAction(row =>
{
if (condition)
{
row.HtmlAttributes["class"] = "someBoldClass";
}
})