Client Side API

call api

GridDemo/ClientSideApi.cshtml
@(Html.Awe().Grid("ApiDemoGrid")
.Columns(new[]{
new Column{Bind = "Id", Width = 55},
new Column{Bind = "Person"},
new Column{Bind = "Food"},
new Column{Bind = "Price"},
new Column{Bind = "Date"},
new Column{Bind = "Location", Group = true}
})
.Height(350)
.Url(Url.Action("GetItems","LunchGrid")))
Awesome/Grid/LunchGridController.cs
public class LunchGridController : Controller
{
public ActionResult GetItems(GridParams g, string person, string food, int? country)
{
food = (food ?? "").ToLower();
person = (person ?? "").ToLower();

var list = Db.Lunches
.Where(o => o.Food.ToLower().Contains(food) && o.Person.ToLower().Contains(person))
.AsQueryable();

if (country.HasValue) list = list.Where(o => o.Country.Id == country);

return Json(new GridModelBuilder<Lunch>(list, g)
{
KeyProp = o => o.Id,// needed for Entity Framework | nesting | tree | api
Map = o => new
{
o.Id,
o.Person,
o.Food,
o.Location,
o.Price,
Date = o.Date.ToShortDateString(),
CountryName = o.Country.Name,
ChefName = o.Chef.FirstName + " " + o.Chef.LastName
}
}.Build());
}
}

Events



Client side api is called by doing $('#gridId').data('api') and an api method

  • .reset() - will bring the grid back to the initial state defined in the markup
  • .load({group, sort, params}) - loads the grid with the specified grouping rules, sorting and additional parameters, if a property is omitted than the grid won't change it's state for that property; for example calling .load({group: ['Food', 'Location']}) will change the grouping but won't affect the current sorting rules
  • .clearpersist() - clears the persistence data