3

Specs

Kendo: 2012.3.1114

.Net: 4.5

MVC: 4.0

Problem

I am binding my grid using a DataTable as the Model and I need to have aggregate values. If I use the snippet below as my base (taken from the Kendo UI Code Library) there seems to be no way to set up the aggregate functions.

@(Html.Kendo().Grid(Model) .Name("Grid") .Columns(columns => { foreach (System.Data.DataColumn column in Model.Columns) { columns.Bound(column.DataType, column.ColumnName); } }) .Pageable() .Sortable() .Scrollable() .Filterable() .Groupable() .DataSource(dataSource => dataSource .Ajax() .Read(read => read.Action("Read", "Home")) ) ) 

Back in the days of the Telerik MVC controls I could set up the aggregate function you could setup the aggregate while adding the bound column but in the Kendo UI wrapper that has been moved down to be inside of the DataSource.

Telerik Grid:

columns.Bound("ColumnName").Aggregate(aggregates => aggregates.Count().Min().Max()) 

If I try and set up the agregate down in the DataSource I get a lovely exception "'count' is undefined" which is a bit vague.

if (column.ColumnName == "ProductID") { columns .Bound(column.DataType, column.ColumnName) .ClientFooterTemplate("Count: #=count#"); } ... .Aggregates(aggregates => { aggregates.Add(a => "ProductID").Count(); }) 

Is there any way to get around the aggregate problem?

1
  • 1
    I guess someone did not like my question. Can you at least tell me what is wrong with it? I looked and there is not a duplicated and I think I made myself clear... Commented Jan 28, 2013 at 21:39

1 Answer 1

8

Though this does not solve the problem with doing sum functions on the datagrid, this answer was provided by the Kendo UI/Telerik support team, and does resolve the question asked above about the count function:

@(Html.Kendo().Grid<dynamic>() .Name("Grid") .Columns(columns => { foreach (System.Data.DataColumn column in Model.Columns) { var boundColumn = columns.Bound(column.ColumnName); if (column.ColumnName == "ProductID") { boundColumn.ClientFooterTemplate("#= data.ProductID !== undefined ? ProductID.count : ''#"); } } }) .Pageable() .Sortable() .AutoBind(false) .Scrollable() .Filterable() .Groupable() .DataSource(dataSource => dataSource .Ajax() .Model(model => { foreach (System.Data.DataColumn column in Model.Columns) { model.Field(column.ColumnName, column.DataType); } }) .Read(read => read.Action("Read", "Home")) ) ) <script> $(document).ready(function () { var grid = $("#Grid").data("kendoGrid"); grid.dataSource.aggregate( [ { field: "ProductID", aggregate: "count" } ]); }); </script> 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.