Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kendo UI Grid Grouping with Aggregate: Use aggregate value of another column in Group header?

I want to use the aggregate value in another column (not the grouping column) in grouping header. For example, here is the demo from Kendo:

http://demos.telerik.com/kendo-ui/grid/aggregates

It aggregate the Units On Order for Units In Stock. I want to show the Average 14 in grouping header (besides Count: 5). Is it possible?

enter image description here

I tried to use template in header,

groupHeaderTemplate: "Units In Stock: #=value# (#=getAverage(data)# / #=count#)"

Then in getAverage(), I calculated the value based on data.

var aggregates = ds.aggregates();
var averaged = aggregates.UnitsOnOrder.average;

However, the average is the average of all rows, not the data within the group.

Any suggestions?

Thanks

like image 886
urlreader Avatar asked Mar 17 '23 00:03

urlreader


1 Answers

You can access the average in data.aggregates, which will contain the aggregates for the relevant group:

groupHeaderTemplate: "Units In Stock: #= value # (Count: #= count#)" +  
                     "(avg: #= aggregates.UnitsOnOrder.average #)"

(demo)

like image 72
Lars Höppner Avatar answered Apr 06 '23 13:04

Lars Höppner