Format numbers in Grid and Footer (sum)

1 Answer 4274 Views
Grid
Mario
Top achievements
Rank 1
Mario asked on 08 Jan 2015, 09:40 AM
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/

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 12 Jan 2015, 07:36 AM
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!
 
Stavros Menegos
Top achievements
Rank 1
commented on 15 Apr 2016, 04:53 PM

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.

 

Rosen
Telerik team
commented on 19 Apr 2016, 05:58 AM

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!
 
Tags
Grid
Asked by
Mario
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or