Cell values can be evaluated on the client side using templates and js functions or on the server side using Map and setting a custom value (as shown here for the Date column).
The group header value can also be set on the server side, same applies for the footer.
Column.ClientFormat - Client format for the column defined as a string using .(ModelPropertyName) for including values of the row model.
Column.ClientFormatFunc - Defines the Name of a javascript function that will receive as a parameter the rowModel of the grid row and must return a string
which will be used a value for the cell. The result of the javascript function will not be encoded.
RowClassClientFormat - used to set the class attribute for grid rows
@*note Column.Bind is not required, but without it you can't Sort/Group by that column*@
<script type="text/javascript"> function formatPrice(lunch, prop) { var color = 'navy'; var price = lunch[prop]; if (price < 20) color = 'green'; if (price > 50) color = 'red'; return "<div style='color:" + color + ";text-width:bold;'>" + price + " £ </div>"; }
.awe-grid .pinkb a, .awe-grid .greenb a { color: blue; }
.postPopup .awe-popup { padding: 1em; } </style>
Demos/Grid/GridDemoController.cs
public async Task<IActionResult> CustomFormatGrid(GridParams g) { var query = mcx.Lunches .Include(o => o.Food) .AsQueryable();
return Json(await new GridModelBuilder<Lunch>(query, g) { Map = o => { var rowcls = o.Price > 90 ? "pinkb" : o.Price < 30 ? "greenb" : string.Empty;
if (o.Date.Year > 2013) rowcls += " date1";
// this will be our row model return new { o.Id, o.Person, o.Price, FoodName = o.Food.Name, Date = o.Date.ToString("dd MMMM yyyy"), o.Location, o.Organic, RowClass = rowcls }; }, MakeHeader = gr => { var value = AweUtil.GetColumnValue(gr.Column, gr.Items.First()).Single(); var strVal = gr.Column == "Date" ? ((DateTime)value).ToString("dd MMMM yyyy") : gr.Column == "Price" ? value + " GBP" : value.ToString();
return new GroupHeader { Content = gr.Header + " - " + strVal }; } }.EFBuildAsync()); // you can use .Build() for non EF datasource (like a List<Lunch> query) }