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?

Rodrigo Juarez
  • 1,745
  • 1
  • 23
  • 38
  • Ok, I found an answer, link here for anyone who need it http://groups.google.com/group/mvccontrib-discuss/browse_thread/thread/f872d298cc9d53dc# – Rodrigo Juarez Jan 23 '11 at 20:56

2 Answers2

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>();
});
ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
Rodrigo Juarez
  • 1,745
  • 1
  • 23
  • 38
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

lentyai
  • 534
  • 1
  • 9
  • 22
  • 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 too – Rodrigo Juarez Mar 25 '11 at 23:02