ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
Grid - Style rows differently based on record property
Title:
B
I
{code}
?
I would like to set the background color of a row in the grid (and other styles) based on a record property. How do you set a custom class on a single row?
Save Changes
Cancel
Michael W Ritchie
asked at 09 Aug 2017
Answers
B
I
{code}
?
set .RowClassClientFormat(".RowClass") and in the controller have this: return Json(new GridModelBuilder<Lunch>(Db.Lunches.AsQueryable(), g) { Map = o => new { ... RowClass = o.Price > 90 ? "pinkb" : o.Price < 30 ? "greenb" : string.Empty } in this example the row will get `pinkb` or `greenb` css class depending on the `Price` property
Save Changes
Cancel
Omu
answered at 09 Aug 2017
Thank you for answering. Your example creates this is the output <tr data-lvl="1" class="awe-row .RowClass"><td>7</td>... Also, where are these types of properties and functions documented? I love the examples at http://aspnetawesome.com/learn/mvc/general but I can't find any documentation of the entire object model.
at 09 Aug 2017
Michael W Ritchie
http://aspnetawesome.com/learn/mvc/Grid#Row-class
at 09 Aug 2017
Omu
Ok, I see. If it's defined in the map, the property value is put in place of the class but if it is not in the map, the contents of the string .RowClassClientFormat("MyClassName") is put in the as <tr class="MyClassName"... Thank you.
at 09 Aug 2017
Michael W Ritchie
please
Sign In
to leave an answer
By accessing this site, you agree to store cookies on your device and disclose information in accordance with our
cookie policy
and
privacy policy
.
OK