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

dataSource number format

14 Answers 1512 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Luke
Top achievements
Rank 1
Luke asked on 04 May 2012, 05:23 PM
Is there any way (or documentation) about formatting numbers in dataSources?

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

Sort by
0
Luke
Top achievements
Rank 1
answered on 04 May 2012, 05:29 PM
Sorry for opening a thread just to solve it again.

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
});

0
Dom
Top achievements
Rank 1
answered on 07 Sep 2012, 08:12 PM
I would like to hear from Kendo team as to why by default it rounds numbers to 2 decimal places? I think that should be configurable instead of writing custom editors for every field...
0
Georgi Krustev
Telerik team
answered on 12 Sep 2012, 10:18 AM
Hello,

 
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.

Regards,
Georgi Krustev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Marcus
Top achievements
Rank 1
answered on 17 Sep 2012, 04:33 AM
As per the original statement, number of decimal places is not a culturally variant property, but should be defined in the specific business case. How would we for instance manage a screen which required two fields, one with two decimal places, and one with three? This is a real situation we have in our application and would need to be able to support.
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...
0
Georgi Krustev
Telerik team
answered on 17 Sep 2012, 09:18 AM
Hello Marcus,

 
In this case you will need to use the decimals property. Here is an example which shows how to achieve your goal.

Greetings,
Georgi Krustev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Marcus
Top achievements
Rank 1
answered on 17 Sep 2012, 10:29 PM
Hi Georgi,

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
0
Georgi Krustev
Telerik team
answered on 18 Sep 2012, 11:04 AM
Hello 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.

Kind regards,
Georgi Krustev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
M
Top achievements
Rank 1
answered on 23 Nov 2012, 08:29 AM
Hi,

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.
0
Teguh
Top achievements
Rank 1
answered on 02 Jun 2016, 06:37 AM

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

0
Daniel
Telerik team
answered on 07 Jun 2016, 05:44 AM
Hello,

How are you posting the data to the server? Could you provide more detailed information about your setup?

Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Teguh
Top achievements
Rank 1
answered on 07 Jun 2016, 06:16 AM

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

0
Daniel
Telerik team
answered on 07 Jun 2016, 08:05 AM
Hi again,

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
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Andreas
Top achievements
Rank 1
answered on 11 Dec 2019, 10:00 AM

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?

0
Tsvetomir
Telerik team
answered on 13 Dec 2019, 02:03 PM

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

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Data Source
Asked by
Luke
Top achievements
Rank 1
Answers by
Luke
Top achievements
Rank 1
Dom
Top achievements
Rank 1
Georgi Krustev
Telerik team
Marcus
Top achievements
Rank 1
M
Top achievements
Rank 1
Teguh
Top achievements
Rank 1
Daniel
Telerik team
Andreas
Top achievements
Rank 1
Tsvetomir
Telerik team
Share this question
or