Example #09: Custom aggregates functions - client side (Ajax)
- Example #9.7: Generic linq and via an inline function and direct usage of a TEntity (without TEntity to TViewModel mappings)
1. Here we can send our view to the client, no need to pass any data yet.
public ActionResult CustomAggregatesFunctionsClientSide()
{
return View();
}
2. Generic linq and via an inline function and direct usage of a TEntity (without TEntity to TViewModel mappings) version:
[ApplyTransaction, GridAction(EnableCustomBinding = true)]
public ActionResult CustomAggregatesFunctionsInlineDirectUsageOfTEntityClientSideData(GridCommand command)
{
// We have to use another query to count because of an issue in NHibernate:
// (currently fixed in the unreleased version 3.3.0) https://nhibernate.jira.com/browse/NH-2846
var query = NHibernateHelper.CurrentSession.Query<Supplier>();
var gridHelper = new GridCustomBindingHelper<Supplier>(command, query)
.AddAggregateFunction(supplier => supplier.SupplierID, queryable => queryable.Select(x => x.SupplierID).Sum(x => x));
var gridModel = gridHelper.BuildGridModel();
return View(gridModel);
}
3. Finaly, the Grid configuration
@(Html.Telerik().Grid<Supplier>().Name("Grid")
.Columns(columns =>
{
columns.Bound(d => d.SupplierID)
.Width(80)
.Aggregate(aggregates => aggregates.Sum())
.ClientGroupFooterTemplate("Custom: <#= Custom #> <br/> Sum: <#= Sum #>")
.ClientFooterTemplate("Custom: <#= Custom #> <br/> Sum: <#= Sum #>");
columns.Bound(d => d.ContactTitle);
columns.Bound(o => o.ContactName);
columns.Bound(d => d.Address);
columns.Bound(d => d.City);
columns.Bound(d => d.PostalCode);
columns.Bound(d => d.Country);
})
.EnableCustomBinding(true).Sortable().Filterable().Pageable()
.DataBinding(dataBinding => dataBinding.Ajax().Select<ExamplesController>(ctr => ctr.CustomAggregatesFunctionsInlineDirectUsageOfTEntityClientSideData(null)))
.Groupable(settings => settings.Groups(groups => groups.Add(o => o.ContactTitle)).Visible(false)))