MvcContrib grid conditional cell formatting based on model value
Asked Answered
A

2

9

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?

Asymmetry answered 23/1, 2011 at 14:34 Comment(1)
Ok, I found an answer, link here for anyone who need it groups.google.com/group/mvccontrib-discuss/browse_thread/thread/…Asymmetry
A
9

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>();
});
Asymmetry answered 20/7, 2011 at 14:58 Comment(0)
H
3

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

Harpoon answered 24/3, 2011 at 20:24 Comment(1)
Hi, thanks! but I think that your answer is for conditional creation, and what I need was conditional formatting. I post a link to a solution from Jeremy tooAsymmetry

© 2022 - 2024 — McMap. All rights reserved.