I have seen the formatting for dates, but I am trying to create a javascript datasource (array) for binding to a kendo grid that contains numbers with 4 decimal places. When the following code runs, it creates a grid with 4 decimal places listed, but when you edit the column it changes to 2 decimal places. Do i need to overwrite the edit function, or am i declaring my format incorrectly?
var mySource = [{"ID":1,"Item":1.1234}];
var myDataSource = new kendo.data.DataSource({
data:mySource,
schema: {
model:{
id:"ID",
fields:{
ID:{type="number"},
Item:{type="number",format:"{n4}"}
}
}
}
});
$('#grid').kendoGrid({
dataSource:myDataSource,
columns:[
{field:"ID",title:"ID"},
{field:"Item",title:"Item",format:"{n4}"}
],
editable:true
});
14 Answers, 1 is accepted

If i create my own editor using kendoNumericTextBox, i am able to set the desired options, such as decimals etc.
It may be useful for someone searching.
$('#grid').kendoGrid({
dataSource:myDataSource,
columns:[
{field:"ID",title:"ID"},
{field:"Item",title:"Item",format:"{n4}", editor:function(container,options){$('<
input
/>').appendTo(container).kendoNumericTextBox({format:"n",decimals:4});}
],
editable:true
});

The length of the fraction (decimal part of the number) depends on the current culture. For instance, the default length of the fraction for the "en-US" culture is 2. I will suggest you check this help topic for more information.
Georgi Krustev
the Telerik team

Currently setting format: "{0:n3}" will correctly display three decimal places, but switching to edit mode reverts to two...?
So entering 123.456 will straight away revert to 123.46...
In this case you will need to use the decimals property. Here is an example which shows how to achieve your goal.
Georgi Krustev
the Telerik team

Thanks for the response, unfortunately this does not work for the inline editing of the grid.
Refer to this example to see what I mean:
http://jsbin.com/welcome/23821/edit
The number will display but as soon as you edit it reverts to two decimals and rounds the number. In my actual example I have three decimals specified in the model of the datasource but this has no effect either.
Thanks,
Marcus
The grid's column does not have a decimal property. You will need to create a custom editor, where to create the NumericTextBox with the requred options. Here is the updated jsBin demo.
Georgi Krustev
the Telerik team

This is exactly the same issue I am having, but unfortunately, the jsbin solution provided is not loading (don't know if it's a temporary problem).
Can you please describe how to format an inline editable Grid to 4 decimal places.
Thank you.

Hi I have an issue with grid inline editing with the number format other than en-us culture.
When I send out decimal data it was "mapped" as null in the Model on the server.
Currently I do workaround by sending out manually using ajax and call the e.preventDefault(); as I could not remove the update method of the grid if the the grid is set for in line edit.
Could you please let us know whether there will be a fix in the next update of the kendo ui grid?
Thanks
How are you posting the data to the server? Could you provide more detailed information about your setup?
Regards,
Daniel
Telerik

Hi Daniel,
Thanks for the reply.
The way the data posted is similar to the sample of in line grid editing. http://demos.telerik.com/aspnet-mvc/grid/editing-inline
But we use web api instead :)
Which does not work for culture other than en-US decimal format.
However, when the data (model) is manually posted by attaching ajax js codes in the on "Save" it works fine. This is our current workaround.
Frankly, we have spent quite number of hours for debugging this issue. We even tried to make custom binding as well as custom serializer which only to realize that it weren't the case.
Warm regards,
TS
The Ajax dataSource sends the data based on the culture because the default controllers expect culture specific format. The WebApi dataSource will format the values independent on the culture using the en-US formats.
Regards,
Daniel
Telerik

Hi Daniel,
i have already described my problem here: https://www.telerik.com/forums/problems-editing-numeric-values-in-the-grid
Now i found this post here and you say:
"The WebApi dataSource will format the values independent on the culture using the en-US formats"
Is that true?
If so, that would mean you can use the .WebApi only in en-US Formats - all other Formats are not able to use the grid when dataSource is set to WebApi?
Hi Andreas,
The WebApi initial implementation has been done for the Invariant culture. Therefore, the culture that is applied on the client-side would automatically get overridden. I have provided more detailed inputs in the forum thread that you have referenced. In case any further questions arise, feel free to post them there.
Have a great end of the week.
Regards,
Tsvetomir
Progress Telerik