how can I apply format 0:c to a grid footer template

1 Answer 3957 Views
Grid
Evgeny Vdovin
Top achievements
Rank 1
Evgeny Vdovin asked on 20 Apr 2012, 07:58 PM
HI 

How can I apply format 0:c to a footertemplate in the Grid.
In one of your example you have avg like this Average: 10.12987012987013 and I think it will be better to present like Average: 10.13

Regards,
Evgeny Vdovin
  

1 Answer, 1 is accepted

Sort by
1
Gergo
Top achievements
Rank 1
answered on 20 Apr 2012, 08:41 PM
Hi Evgeny,

You can use the kendo.toString() method to format the footerTemplate,
Please see this example below:

$("#grid").kendoGrid({
           dataSource: {
               data: [
                   {
                       OrderId: 1,
                       NrOfProducts: 2,
                       Price: 155.9987
                   },
                   {
                       OrderId: 2,
                       NrOfProducts: 12,
                       Price: 987.44587
                   },
                   {
                       OrderId: 3,
                       NrOfProducts: 22,
                       Price: 0.7878
                   }
                   ],
 
               aggregate: [
               { field: "NrOfProducts", aggregate: "sum" },
               { field: "Price", aggregate: "sum"}]
           },
           sortable: true,
           scrollable: false,
           columns: [{
               field: "OrderId",
               title: "ID of the Order"
           },
           {     field: "NrOfProducts",
               title: "Number Of Products",
               footerTemplate: "Total Products : #= kendo.toString(sum, '0.00') #"
           },
           {    field: "Price",
               title: "Price",
               footerTemplate: "Total Price: #= kendo.toString(sum, 'C') #"
            }]
       });


Kind Regards,
Gergő
Evgeny Vdovin
Top achievements
Rank 1
commented on 20 Apr 2012, 09:18 PM

Thanks a lot

Regards,
Evgeny Vdovin
Dr.YSG
Top achievements
Rank 2
commented on 18 Jun 2013, 03:58 PM

And if I want to do that for this bit of HTML (I am running out of quote options)?

01.data-columns='[
02.    "Class",
03.    "Type",
04.     {field: "FileCount",
05.     format: "{0:n2} MB",
06.     aggregates: ["sum"],
07.     footerTemplate: "Total: #=data.FileCount? data.FileCount.sum : 0 #"
08.    },
09.    {field: "Size",
10.     format: "{0:n2} MB",
11.     aggregates: ["sum"],
12.     footerTemplate: "Total: #=data.Size?data.Size.sum : 0 # MB"
13.    },
14.    {field: "Date",
15.     format: "{0:F}" },
16.    "Path",
17.    {command: "destroy"},
18.]'>
Alexander Valchev
Telerik team
commented on 21 Jun 2013, 07:17 AM

Hello Dr.YSG,

You can use backslash to escape quotation marks:
"Total: #= kendo.toString(data.FileCount ? data.FileCount.sum : 0, \"n2\") # MB"


Regards,
Alexander Valchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Philip
Top achievements
Rank 1
commented on 19 Jun 2014, 03:48 PM

I'm using KendoUI 2014.1.528

I'm trying to format a footer as well using this:

footerTemplate: "#= kendo.tostring(average, \"n2\") #"

I get "JavaScript runtime error: Object doesn't support property or method 'tostring'"

Am I doing something wrong?
Reqs
Top achievements
Rank 1
commented on 19 Jun 2014, 04:32 PM

bsimms, try toString instead of tostring?
Tags
Grid
Asked by
Evgeny Vdovin
Top achievements
Rank 1
Answers by
Gergo
Top achievements
Rank 1
Share this question
or