This project is read-only.

style the cell dynamically?

May 17, 2016 at 2:45 PM

I have a need to colour in cells in a grid according to their status. I have a view model that handles the business logic and provides the style name I'd like. What's the best way to achieve this? Ideally this would work:

columns.Add(foo => foo.MyFieldStatusText).Css(foo => foo.MyFieldStatusStyle);

However css is just a string.

Should I render value as in a span and try and style it from there? Or use jquery to apply a span's style to it's parent? Has anyone else done this?

Many thanks,

Jun 14, 2016 at 11:01 AM
Use the SetRowCssClasses method which can be used on the grid itself. E.g. not on the column itself.:

}).WithPaging(30).Sortable().WithMultipleFilters().SetRowCssClasses(columns =>
                                              if ( decimal.Parse(columns.ActualCost.Replace("£", "")) < decimal.Parse(columns.ExpectedCost.Replace("£", "")))
                                                  return "danger";

                                              return string.Empty;