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?
MvcContrib grid conditional cell formatting based on model value
Asked Answered
Ok, I found an answer, link here for anyone who need it groups.google.com/group/mvccontrib-discuss/browse_thread/thread/… –
Asymmetry
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>();
});
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
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 –
Asymmetry
© 2022 - 2024 — McMap. All rights reserved.