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

Aggregate totals for nested data

1 Answer 302 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Troy
Top achievements
Rank 1
Troy asked on 03 Jun 2016, 04:23 PM

I've got "nested" json data that I'm attaching as local data to the datasource of a grid.  Each row has some normal "flat" values (like "rowID"), and also "keyedInfo" array, which in turn is also an array (keys like "key1" and "key2") where one attribute of each element ("theVal") is of interest for displaying as a grid column.  I've got a simple example in the dojo:

I'm never to sure how much support the DataSource has for nested data, but by specifying "keyedInfo: {}" in the dataSource fields definition, this mostly works!  I can specify "keyedInfo['key1'].theVal" as an entry in the grid's "columns" definition, and it displays the appropriate value from the data.  I can also, as expected, do aggregate totals of the flat attributes (like "count" on rowID).  However, there doesn't seem to be any way to aggregate the columns that are from the nested values.

I have {field: "keyedInfo['key1'].theVal, aggregate: "sum"} entries in the dataSource aggregate definition, and it doesn't raise any errors, so it is either being ignored or actually calculating the aggregate.  But a footerTemplate of "#=sum# for these sorts of columns raises a Javascript error that "sum" isn't defined (uncomment one of them in the dojo example to see this).  Is there any chance that the aggregate has been calculated and I just need a more complex reference in the template?

If not, is there any hope that support might get extended to this case?  I suspect that the lack of definition support in the "schema" may be preventing the aggregate from having a way to refer/store the desired aggregate, but it would be very nifty if a way could be found - flattening the data source will be a pain.

1 Answer, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 07 Jun 2016, 11:44 AM

Hello Troy,

The Kendo UI DataSource is designed to operate with flat data which is why there is no specified type for 'object' or 'array'. Internally it expects the data to be in flat structure in order aggregate's calculate and etc. to work properly.  

As a possible workaround you can use functions for the footer template as shown in http://dojo.telerik.com/ahUMI/6 example. Please note that this is not officially supported scenario (to have a nested data and calculate aggregates for nested data), so in some cases it might not work as expected. 

Regards,
Boyan Dimitrov
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
Troy
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Share this question
or