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

Kendo Grid - Aggregate not working on complex data objects

4 Answers 425 Views
Grid
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 14 Nov 2012, 10:43 PM

I have a Kendo UI grid. The grid has a datasource with complex object data. For example, {"foo": {"bar" : 10}}. Although the column field can navigate the object graph (i.e. foo.bar), the aggregate field doesn't seem to be able to.

Here's the code:

var grid = $("#grid").kendoGrid({
   dataSource: {
       data: [
           {"foo": {"bar": 10}},
           {"foo": {"bar": 20}}
       ],

       aggregate: [
           {field: "foo.bar", aggregate: "sum"}
       ]  
   },
   columns: [
       {
           field: "foo.bar",
           footerTemplate: "Sum: #= sum # "
      }
  ]   
}).data("kendoGrid");

Here's the fiddle: http://jsfiddle.net/e6shF/1/

Firebug reports "TypeError: data.foo is undefined" in line 8 of kendo.all.min.js.

Am I doing something incorrectly? If this is a bug in Kendo, is there a way to work around this? I have to keep the objects complex.

4 Answers, 1 is accepted

Sort by
0
wizmagister
Top achievements
Rank 2
answered on 22 Nov 2012, 01:58 PM
Hello, I've noticed the same thing. I'll take this up to the support team and post back the answer. Thanks !
0
wizmagister
Top achievements
Rank 2
answered on 23 Nov 2012, 08:41 PM
Hello, as promised, here's Kendo solution :

The behavior you are experiencing is caused by the fact that the "path" you have specified will be used as a key in the map created as result of the aggregation. Producing a object similar to the following:

{ "foo.bar" :  { sum: 30 } }

Unfortunately, this construct is not supported by the footer template generation and will not be resolved correctly. A possible workaround for this scenario is to use a function instead. I have modify the sample in order to illustrate this.

var
grid = $("#grid").kendoGrid({ dataSource: { data: [ {"foo": {"bar": 10}}, {"foo": {"bar": 20}} ], aggregate: [ {field: "foo.bar", aggregate: "sum"} ] }, columns: [ { field: "foo.bar", footerTemplate: function(data) { return "Sum: " + data["foo.bar"].sum; } } ] }).data("kendoGrid");
0
alisakhi
Top achievements
Rank 1
answered on 01 Sep 2014, 08:40 PM
How will this work on groupfooterTemplate? I tried this the result is coming 0.
0
Alexander Popov
Telerik team
answered on 04 Sep 2014, 02:32 PM
Hello alisakhi,

This could be achieved by specifying the columns.aggregates, as shown in this example.

Regards,
Alexander Popov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
James
Top achievements
Rank 1
Answers by
wizmagister
Top achievements
Rank 2
alisakhi
Top achievements
Rank 1
Alexander Popov
Telerik team
Share this question
or