位/整数/字符串字段中的Telerik网格行自定义格式 [英] Telerik Grid Row Custom Formatting on either bit/int/string field

查看:101
本文介绍了位/整数/字符串字段中的Telerik网格行自定义格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我更喜欢使用string或int,但会根据位来解决.

目标是,如果String字段的值=='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唯一清晰的示例,说明如何执行此操作,这样任何人都有任何想法吗?

解决方案

Well花了很长时间,但telerik最终承认Cellaction在开源版本上存在一个错误,他们已经在商业版本(http://www .telerik.com/community/forums/aspnet-mvc/grid/cell-action-issue-evidence-provided.aspx),只有两个锁定的主题,直到他们最终接受了我一直在告诉他们的内容./p>

长话短说,如果您想执行类似的操作,那么Cellaction就会遇到问题,然后购买商业版或按照以下步骤操作.

为每个要更改颜色的单元格简单地在DTO中添加一个额外的字段,在我的情况下,我有6个日期,具体取决于它们与当前日期的接近程度会改变颜色.

然后,您将在控制器中进行所有日期计算,并根据其接近程度将颜色记录为其对应的DTO项目.

例如

public String DateDisplay1
public String DateDisplay1Colour

然后,您将在网格上隐藏颜色项,并使用其值更改DateDisplay1所在的行的颜色.

因此,如果DateDisplay1位于row1上,那么在onRowDataBound(e)函数中,我将得到类似的信息

if (e.dataItem.DateDiplay1Colour == "Green") {

        e.row.cells[1].style.backgroundColor = "#7EDF7D";
    }

这样,您仍然可以在单元格中显示日期,然后根据其相应的隐藏值显示颜色.

然后可以通过管理员权限进行操作,因此,如果用户不是管理员,则

row.cells[6].innerHTML = '<readonly>' + "Edit" + '</readonly>';

因此摆脱了允许用户编辑该记录的链接.

希望这对某些人有帮助,我希望telerik能够解决我的主题问题,以便我补充发现的解决方案.

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?

解决方案

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

public String DateDisplay1
public String DateDisplay1Colour

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

if (e.dataItem.DateDiplay1Colour == "Green") {

        e.row.cells[1].style.backgroundColor = "#7EDF7D";
    }

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

row.cells[6].innerHTML = '<readonly>' + "Edit" + '</readonly>';

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.

这篇关于位/整数/字符串字段中的Telerik网格行自定义格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆