This is a migrated thread and some comments may be shown as answers.

DataTable aggregete functions

1 Answer 171 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mohammad
Top achievements
Rank 1
Mohammad asked on 25 Jan 2013, 07:36 PM

Specs

Kendo: 2012.3.1114
Net: 4.5
MVC: 4.0

Problem
I am binding my grid using a DataTable as the Model and need to have aggregate values.  I have to use the datatable as I have a lot of data that is being sent over from the web service.  If wrapped as XML it was over 55 MB for 21 columns and 14,400 rows so we converted the SQL DataTable to CSV and then sent the string over.  That resulted in a file around 5MB.

The data that I a getting has no model as there can easily be 200+ columns depending on the query so making a data model is sadly out of the question.

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 Answer, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 29 Jan 2013, 11:26 AM
Hello Mohammad,

An aggregate could not be declared this way:

.Aggregates(aggregates =>
{
aggregates.Add(a => "ProductID").Count();
})

but with a membership expression:
.Aggregates(aggregates =>
{
aggregates.Add(a => a.ProductID).Count();
})

which cannot be done in your case. The reason why an exception is thrown, is that the serializer does not know to which column is the aggregate applied.

I am attaching a sample project with a workaround approach. You could set the autobind to false and add the aggregates on document ready using the aggregate method of the dataSource.


All the best,
Dimiter Madjarov
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Mohammad
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Share this question
or