Format numbers in Grid and Footer (sum)

4 posts, 0 answers
  1. Mario
    Mario avatar
    6 posts
    Member since:
    Dec 2014

    Posted 08 Jan 2015 Link to this post

    Hi

    I am trying to format my data as per http://docs.telerik.com/kendo-ui/framework/globalization/numberformatting

    This is my example:

    http://jsfiddle.net/Lqxon2f1/2/

    After I format my data is looks like it is not recognized as number anymore and hence not summed up properly.

    Also I am unsure how to format the sum displayed in my footer column

    Help appreciated!

    BR

    http://jsfiddle.net/Lqxon2f1/2/
  2. Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 12 Jan 2015 Link to this post

    Hello Mario,

    You should not format the actual data as this indeed, this will convert it to a string. Instead you should use the column.format to set the appropriate format. In order to apply formatting to the aggregate's value you can use the kendo.toString.

    $("#grid").kendoGrid({
      columns: [
        { field: "name", footerTemplate: "Silvan Bla" },
        { field: "age",
         footerTemplate: "Sum: #: kendo.toString(sum, '\\#\\#,\\#') #",
       format: "{0:##,#}"
        }
      ],
      dataSource: {
        data: [
          { name: "Jane Doe", age: 12345678 },
          { name: "John Doe", age: 3333 },
          { name: "John Doe", age: 2223 }
        ],
        aggregate: [
            { field: "age", aggregate: "sum" } )
        ]
      }
    });


    Regards,
    Rosen
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. Kendo UI is VS 2017 Ready
  4. Stavros Menegos
    Stavros Menegos avatar
    5 posts
    Member since:
    Jul 2006

    Posted 15 Apr in reply to Rosen Link to this post

    Hi,

    I am referring to formatting the aggregate value part of the answer. I believe that the suggested answer forces the developer to do plumbing work. Should someone has defined a format string for a column, as you did in your answer, the corresponding footer template should at least by default follow that format for the aggregate values.

    As you write, having a format string we have to know its structure in order to safely produce a kendo.tostring equivalent format for the aggregate in the footertemplate. Which is no good.

     

  5. Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 19 Apr Link to this post

    Hello Stavros,

     

    Generally speaking having a template definition imply that the developer is responsible for defining the content rendered by this template. Aggregate values' type does not always match the type of the original data - for example count of a string column. Therefore, it is not always possible to guess the format of the aggregate. Also there could be multiple aggregates for a single column, which to be arranged in some free form. This is way it is up to the developer to decide how to construct the template.

     

    Regards,
    Rosen
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
Back to Top
Kendo UI is VS 2017 Ready