# How to set formula to calculate in groupHeaderTemplate

1. ##### krishnan
5 posts
Member since:
Nov 2015

Posted 02 Sep 2016 Link to this post

Hi,

I would like to know how to set the group header template which displays data after calculating from multiple column values. The formula is something like sum(col_x_value * col_y_value) / sum of col_x_value after grouping. This data should display for each and every grouped header.

2. ##### Kiril Nikolov
2598 posts

Posted 06 Sep 2016 Link to this post

Hi,

You can execute a function inside the template. Please see the following example:

http://dojo.telerik.com/AHUzO

Regards,
Kiril Nikolov
Telerik by Progress

Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.

3. ##### krishnan
5 posts
Member since:
Nov 2015

Posted 06 Sep 2016 in reply to Kiril Nikolov Link to this post

Hi,

In http://dojo.telerik.com/AHUzO only "age" value is getting passed to the foo function. How can I pass other column values to it?.

Please find the code snippet here

I want to display Percentage : Sum ( item1 values in that group * item2 values in that group ) / sum ( item1 values in that group )

For example, the first group should display Percentage : 27.5

( (21 * 28) + (21 * 27) ) / (21 + 21) = 1155 / 42 = 27.5

Thanks.

4. ##### krishnan
5 posts
Member since:
Nov 2015

Posted 06 Sep 2016 in reply to Kiril Nikolov Link to this post

Hi,

In http://dojo.telerik.com/AHUzO only age field value is getting passed to the foo function. How to pass other column values to it?

Please find the code snippet here.

I want to display Percentage value in each group header.

Example:

Percentage : Sum ( item1 values in that group * item2 values in that group ) / sum ( item1 values in that group )

For the first group: ( ( 21 * 28 ) + ( 21 * 27 ) ) / ( 21 + 21 )  = 1155 / 42 = 27.5

So, first group header should display Percentage : 27.5

Also, please let me know if I can set group header template globally.

Thanks

5. ##### Kiril Nikolov
2598 posts

Posted 08 Sep 2016 Link to this post

Hello,

In the function you can just get a reference to the dataSource and get all the aggregates using the aggregates method documented here:

http://docs.telerik.com/kendo-ui/api/javascript/data/datasource

Regards,
Kiril Nikolov
Telerik by Progress

Get started with Kendo UI in days. Online training courses help you quickly implement components into your apps.