How to style rows in the MVCContrib Grid based on their data?

后端 未结 1 1322
难免孤独
难免孤独 2021-02-04 13:08

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 eac

1条回答
  •  -上瘾入骨i
    2021-02-04 13:46

    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" : ""))
    

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

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

    Sorry for the long code snippet...

    0 讨论(0)
提交回复
热议问题