Duration format

2 posts, 0 answers
  1. Daniel
    Daniel avatar
    13 posts
    Member since:
    May 2016

    Posted 30 May 2016 Link to this post

    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?

  2. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3747 posts

    Posted 31 May 2016 Link to this post

    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!
     
Back to Top