Telerik 网格行在位/整数/字符串字段上自定义格式
我更喜欢字符串或整数,但会根据位来解决。
目标是如果字符串字段的值=='blah blah blah',它将把整行变成灰色(已经使用了红色和绿色的蓝色表格,所以我愿意接受任何其他颜色建议)
我已经尝试
.RowAction(row =>
{
if (row.DataItem.[Bound Data col Name] == "[String value]")
{
row.HtmlAttributes["style"] = "background:grey;";
}
})
,
.RowAction(row =>
{
if (row.DataItem.[Bound Data col Name] == "[String value]")
{
row.Grid.HtmlAttributes["style"] = "background:grey;";
}
})
过
.ClientEvents(events => events.OnRowDataBound("onRowDataBound"))
function onRowDataBound(e) {
if (e.dataItem.[Bound Data col Name] == "[String value]") {
e.row.style.backgroundColor = "grey";
}
}
所有这些都没有丝毫作用,这些是 mvc 关于如何做到这一点的唯一明确的例子,所以有人有任何想法吗?
I'd prefer for either string or int but would settle for it based on bit.
The Goal is if the value of a String field == 'blah blah blah' that it will turn that whole row grey(blue table with red and green already used on it so I'm open to any other colour suggestion)
I've tried
.RowAction(row =>
{
if (row.DataItem.[Bound Data col Name] == "[String value]")
{
row.HtmlAttributes["style"] = "background:grey;";
}
})
and
.RowAction(row =>
{
if (row.DataItem.[Bound Data col Name] == "[String value]")
{
row.Grid.HtmlAttributes["style"] = "background:grey;";
}
})
and
.ClientEvents(events => events.OnRowDataBound("onRowDataBound"))
function onRowDataBound(e) {
if (e.dataItem.[Bound Data col Name] == "[String value]") {
e.row.style.backgroundColor = "grey";
}
}
all of these didn't work in the slightest and these are the only clear examples for mvc on how to do this so anybody got any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
花了很长时间,但 Telerik 最终承认开源版本上的 Cellaction 存在一个错误,他们已在商业版本上解决了该错误(http://www.telerik.com/community/forums/aspnet-mvc/grid/cell- action-issue-evidence-provided.aspx),只用了 2 个锁定的主题,他们就最终接受了我一直告诉他们的内容。
长话短说,如果您想做这样的事情,但遇到 Cellaction 问题,那么要么购买商业版本,要么按照以下步骤操作。
只需在 DTO 中为每个要更改颜色的单元格添加一个额外的字段,在我的例子中,我有 6 个日期,根据它们与当前日期的接近程度,它们的颜色会发生变化。
然后,您将在控制器中执行所有日期计算,并根据其接近程度将颜色记录到其相应的 DTO 项。
例如
,您可以隐藏网格上的颜色项,并使用它的值来更改 DateDisplay1 所在行的颜色。
因此,如果 DateDisplay1 位于 row1 上,那么在 onRowDataBound(e) 函数中,我会采用类似的
方式,您仍然可以在其单元格中显示日期,然后根据其相应的隐藏值显示颜色。
然后可以使用管理员权限完成相同的操作,因此如果用户不是管理员,则
可以删除允许用户编辑该记录的链接。
希望这对一些人有帮助,我希望 Telerik 能抽出时间来解锁我的主题,以便我可以添加我找到的解决方案。
Well took forever but telerik finally admitted that there was a bug with Cellaction on the open source version which they had address on the commercial version (http://www.telerik.com/community/forums/aspnet-mvc/grid/cell-action-issue-evidence-provided.aspx), it only took 2 locked topics until they finally accepted what I'd been telling them the whole time.
Long story short if you want to do something like this an encounter issues with Cellaction then either buy the commercial version or follow the steps below.
Simple add an extra field into your DTO for each cell you want to change the colour of, in my case I had 6 dates which depending on how close to present date they got would vary their colour.
You would then in the controller do all the date calculations and depending on how close it got would record the colour to it's corresponding DTO item.
for example
then you would hide the colour item on the grid and use it's value to change the colour of the row which DateDisplay1 is on.
so if DateDisplay1 is on row1 then in the onRowDataBound(e) function I would have something like
this way you can still display the date in it's cell and then display the colour based off it's corresponding hidden value.
then same can be done with admin powers so if a user isn't an admin then
thus getting rid of the link allowing a user to edit that record.
Hope this helps some people and I hope telerik gets round to unlocking my topics so I can add on the solution I found.