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

Duration format

1 Answer 196 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 30 May 2016, 09:59 AM

My json data for this cells is String i.e. :  "05:20"   {HH:mm} format.

Here is my grid options for this column:

column ...  { title: 'Jazdy', field: 'driving_time', footerTemplate: "#= data.driving_time.sum #"}

aggregate ... { field: "driving_time", aggregate: "sum" }

schema ... model: { fields: { driving_time: { type: "duration" }, ...} ...}

So in this scenario in footer i see value only from last row. How to make it properly to get summary duration in footer?

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 01 Jun 2016, 07:30 AM
Hello Daniel,

The described behavior is actually expected, because sum aggregator would not be able to sum string values. At least it doesn't have any notion what is the number representation of that string value.

The solution in this case is to convert the string value into number, which could be calculated properly. Then you can use custom formatting function that will know how to convert that number into TimeSpan duration value. Basically, the steps are:
  1. Convert driving_time to number
  2. Implement a custom JavaScript function that will convert the number into timespan:
footerTemplate: "#= format_timespan(data.driving_time.sum) #"
where format_timespan is a custom function accessible from the global scope:
window.format_timespan = function(duration) { /* format duration here */ }

Regards,
Georgi Krustev
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
Daniel
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or