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

Dynamic number format in grids?

2 Answers 205 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marcus
Top achievements
Rank 1
Marcus asked on 12 Sep 2012, 07:53 AM
Is it possible to format numbers based on variable rather than fixed values? I know that there are various ways you can
do this normally, like padding etc but is it possible to do something directly in the grid?

This is very important btw.

2 Answers, 1 is accepted

Sort by
0
OnaBai
Top achievements
Rank 2
answered on 12 Sep 2012, 09:09 AM
If you mean assign a format contained in a variable in creation time, you should do:
var format = "n2";
// For kendoNumericTextBox
var number = $("#number").kendoNumericTextBox({
    format:format,
    value:12.34
}).data("kendoNumericTextBox");
// and for kendoGrid
var gridFormat = "{0:n2}"
var grid = $("#number").kendoGrid({
    dataSource:dataSource,
    columns:[
        ....
        {title:"Number", field:"number", format:gridFormat },
        ....
    ],
    editable:true
});
If you mean change the format as response to an event (for example, a click) then you should invoke the following code:
// for numeric text box
number.options.format =
"n3";
// for grid
grid.columns[colNumber].format = "{0:n3}"
For changing the format and then forcing a refresh of the field (writing its own value)
// for numeric text box
number.value(number.value());
// for grid
grid.refresh();
Hope this works!!!
0
Marcus
Top achievements
Rank 1
answered on 12 Sep 2012, 09:48 AM
This looks like it could work. I will try and get back to you. Thank you in advance.

Sorry, I was not clear enough. What I mean is that I have a second lookup field that contains the number of decimals for that field. It is a type of BI-solution where there is alot of different type of data depending on what KeyFigure you have.

So in short. Is it possible to have the format defined by a dynamic variable. Maybe by using string padding or some type of function.
Tags
Grid
Asked by
Marcus
Top achievements
Rank 1
Answers by
OnaBai
Top achievements
Rank 2
Marcus
Top achievements
Rank 1
Share this question
or