Cascading grids

Click on the rows of the first grid to select categories and watch the second grid reload.



CascadingGridDemo/Index.cshtml
@(Html.Awe().Grid("CategoriesGrid")
.Groupable(false)
.Url(Url.Action("CategoriesGrid"))
.Columns(new Column { Bind = "Name" })
.Selectable(SelectionType.Multicheck))
<br />
@(Html.Awe().Grid("MealsGrid")
.Groupable(false)
.MinHeight(200)
.Url(Url.Action("MealsGrid"))
.Columns(new Column { Bind = "Name" }))

<script>
$(function () {
$('#CategoriesGrid')
.on('aweselect aweload', function () {
var selectedIds = $(this).data('api').getSelection().map(function (o) { return o.Id; });
$("#MealsGrid").data('api').load({ params: { categories: selectedIds } });
});
});
</script>
Demos/Grid/CascadingGridDemoController.cs
public ActionResult CategoriesGrid(GridParams g)
{
return Json(new GridModelBuilder<Category>(Db.Categories.AsQueryable(), g)
{
Key = "Id"
}.Build());
}

public ActionResult MealsGrid(GridParams g, int[] categories)
{
categories = categories ?? new int[] { };

return Json(new GridModelBuilder<Meal>(Db.Meals.Where(o => categories.Contains(o.Category.Id)).AsQueryable(), g).Build());
}