如何根据他们的数据样式在MVCContrib网格行? [英] How to style rows in the MVCContrib Grid based on their data?

查看:142
本文介绍了如何根据他们的数据样式在MVCContrib网格行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 MVCContrib电网修修补补和我停留在如何格式化数据行在基于数据的网格。

I am tinkering with the MVCContrib Grid and am stuck on how to format a row of data in the grid based on the data.

举例来说,假设我们有一个产品的网格,其中每个产品都有类似的名称,价格和停产数据字段。我想强调指出的停产所有的产品行。

For example, say we have a grid of products, where each product has data fields like name, price, and discontinued. I'd like to highlight all product rows that are discontinued.

一个解决方法是使用jQuery在客户端,以一个CSS类适用于那些停产细胞是TRUE的行,但是这似乎是一个脆弱的解决方案。我希望有一种方法做它通过 Html.Grid 方法调用服务器端。

One workaround would be to use jQuery on the client-side to apply a CSS class to those rows where the discontinued cell is TRUE, but that seems like a brittle solution. I'm hoping there's a way to do it on the server-side via the Html.Grid method call.

感谢

推荐答案

您好斯科特:尝试类似以下内容添加RowAttributes -

Hello Scott: Try something like the following to add RowAttributes -

@Html.Grid(Model)
    .WithModel(new CustomerGridModel())
    .Sort(ViewData["sort"] as GridSortOptions)
    .Attributes(id => "grid", style => "width: 100%;")
    .RowAttributes(data => new MvcContrib.Hash(
        @class => data.Item.Discontinued ? "discontinued" : ""))

这将一个类属性添加到tr元素。然后,创建的线沿线的一类:

This will add a class attribute to the tr element. Then, create a class along the lines of:

tr.discontinued td {background-color: red;}

很抱歉的长期code片段...

Sorry for the long code snippet...

这篇关于如何根据他们的数据样式在MVCContrib网格行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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