Question

I need to conditional formatting a cell value based on a boolean value in the model. I have the column col.For(item => item.Detail); If item.Unfinished I need to apply some css style How can I do that?

Was it helpful?

Solution

The answer is in my comment to the original post:

http://groups.google.com/group/mvccontrib-discuss/browse_thread/thread/f872d298cc9d53dc

column.For(x => x.Surname).Attributes(x => {
    if(x.Item.Surname == "foo") {
        return new Dictionary<string, object> { { "style", "color:red"} };
    }
    return new Dictionary<string, object>();
});

OTHER TIPS

if you still looking for solution:

" The above property of the MVCContrib grid also does the trick.

<%= Html.Grid(Model.Services).AutoGenerateColumns()
    .Columns(column => {
        column.For(a => Html.ActionLink("Editar", "Edit", new { id = a.Id }))
            .InsertAt(0).Encode(false)
            .CellCondition(x => 
                (x.CreatedBy==Membership.GetUser().UserName));
    })
    .Sort(Model.GridSortOptions)
    .Attributes(@class => "table-list")
    .Empty(Resources.NO_DATA_TO_DISPLAY)
%>

"

Credits to Jeremy Skinner http://www.jeremyskinner.co.uk/2010/04/27/mvccontrib-grid-part-7-auto-generated-columns/comment-page-1/#comment-19059

and jpassos who originally posted it here: http://forums.asp.net/p/1559843/3850767.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top