How do you create a Calculated Footer

3 Answers 1217 Views
Grid
Wyatt
Top achievements
Rank 1
Wyatt asked on 02 May 2013, 02:01 PM
for KendoGrid I want to make a calculated footer.  Take the total of column A and the total of column B and divide them.

3 Answers, 1 is accepted

Sort by
0
Accepted
Alex Gyoshev
Telerik team
answered on 03 May 2013, 09:06 AM
Hello Wyatt,

You can achieve this through the DataSource aggregates and a column footer template. See the grid aggregates demo and this jsBin showing how to access data across columns.

All the best,
Alex Gyoshev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Joe
Top achievements
Rank 1
commented on 06 Aug 2013, 10:27 PM

How would you then take your calculated footer template example and apply #=kendo.toString(sum,'P2')# equivalent?
Thanks.
Alfredo
Top achievements
Rank 1
commented on 13 May 2015, 03:44 PM

How would you handle a case where the Denominator in the calculation is 0 (thus divide by zero).  In my grid, where I format as Currency, it displays 'INFINITY'
0
Joe
Top achievements
Rank 1
answered on 06 Aug 2013, 10:33 PM
I've answered my own question. The solution for my calculated cross columns was:
.ClientFooterTemplate("<div>Avg: #= kendo.toString(data.TotalMarginAmt.sum / data.TotalSalesAmt.sum,'P2') # </div>")
0
Alex Gyoshev
Telerik team
answered on 14 May 2015, 09:08 AM

Hello Alfredo,

You can have conditional expressions in templates, so you can handle this separately:

    # if (isZero) { #
       N/A
    # } else { #
       formatted value
    # } #

 

Regards,
Alex Gyoshev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Alfredo
Top achievements
Rank 1
commented on 14 May 2015, 03:09 PM

Alex,

Thanks for your reponse.  What I ended up doing was using a function in the template to check for zero.  I will try your solution next time I run into this situation.

Alfredo

Tags
Grid
Asked by
Wyatt
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Joe
Top achievements
Rank 1
Share this question
or