Example #07: Aggregates client side (Ajax)

1. The only configuration required is on the view.
@(Html.Telerik().Grid<ProductModel>().Name("Grid")
        .Columns(columns =>
        {
            columns.Bound(x => x.ProductName)
                .Aggregate(aggregates => aggregates.Count())
                .ClientGroupFooterTemplate("Count: <#= Count #>")
                .ClientFooterTemplate("Total Count: <#= Count #>");

            columns.Bound(o => o.UnitPrice)
                .Width(200)
                .Aggregate(aggreages => aggreages.Sum())
                .Format("{0:c}")
                .ClientGroupFooterTemplate
                    ("Sum: <#= $.telerik.formatString('{0:c}', Sum) #>")
                .ClientFooterTemplate
                    ("Total Sum: <#= $.telerik.formatString('{0:c}', Sum) #>");

            columns.Bound(o => o.UnitsOnOrder)
                .Width(200)
                .Aggregate(aggregates => aggregates.Average())
                .ClientGroupFooterTemplate("Average: <#= Average #>")
                .ClientFooterTemplate("Average: <#= Average #>");

            columns.Bound(o => o.UnitsInStock)
                .Width(100)
                .Aggregate(aggregates => aggregates.Count().Min().Max())
                .ClientGroupHeaderTemplate
                    ("<#= Title #>: <#= Key #> (Count: <#= Count #>)")
                .ClientFooterTemplate
                    ("<div>Min: <#= Min #></div>" + "<div>Max: <#= Max #></div>");
        })
        .EnableCustomBinding(true).Sortable().Filterable().Pageable()
        .DataBinding(dataBinding => dataBinding.Ajax()
            .Select<ExamplesController>(ctr => ctr.AggregatesClientSideData(null)))
        .Groupable(settings => settings.Groups(groups => groups
            .Add(o => o.UnitsInStock)).Visible(false)))

Last edited Feb 27, 2012 at 11:14 PM by Luis_Fernando, version 2

Comments

No comments yet.