Aggregates
The TreeList enables you to display aggregated number results when the user groups its data.
To enable the aggregate functions, use the DataSource.Aggregates()
and the FooterTemplate()
methods of the TreeList, and the aggregate
fields of its data source.
@(Html.Kendo().TreeList<Kendo.Mvc.Examples.Models.TreeList.EmployeeDirectoryModel>()
.Name("treelist")
.Columns(columns =>
{
columns.Add().Field(e => e.Extension).Title("Ext")
.FooterTemplate("Tota: #= count #, Sum: #= sum #, Min: #= min #, Max: #= max #, Average: #= average #");
})
.DataSource(dataSource => dataSource
.ServerOperation(false)
.Read(read => read.Action("All", "EmployeeDirectory"))
.Aggregates(aggr =>
{
aggr.Add(e => e.Extension).Count().Sum().Max().Min().Average();
})
.Model(m =>
{
m.Id(f => f.EmployeeId);
m.ParentId(f => f.ReportsTo);
m.Field(f => f.ReportsTo);
})
)
)
For a runnable example, refer to the demo on using aggregate functions in the TreeList.