dataSource number format

13 posts, 0 answers
  1. Luke
    Luke avatar
    6 posts
    Member since:
    Jul 2011

    Posted 04 May 2012 Link to this post

    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
    });
  2. Luke
    Luke avatar
    6 posts
    Member since:
    Jul 2011

    Posted 04 May 2012 Link to this post

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

  3. Kendo UI is VS 2017 Ready
  4. Dom
    Dom avatar
    7 posts
    Member since:
    Jun 2011

    Posted 07 Sep 2012 Link to this post

    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...
  5. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3706 posts

    Posted 12 Sep 2012 Link to this post

    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!
  6. Marcus
    Marcus avatar
    15 posts
    Member since:
    Dec 2007

    Posted 16 Sep 2012 Link to this post

    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...
  7. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3706 posts

    Posted 17 Sep 2012 Link to this post

    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!
  8. Marcus
    Marcus avatar
    15 posts
    Member since:
    Dec 2007

    Posted 17 Sep 2012 Link to this post

    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
  9. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3706 posts

    Posted 18 Sep 2012 Link to this post

    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!
  10. M
    M avatar
    29 posts
    Member since:
    Oct 2012

    Posted 23 Nov 2012 Link to this post

    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.
  11. Teguh
    Teguh avatar
    6 posts
    Member since:
    May 2015

    Posted 02 Jun Link to this post

    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

  12. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 07 Jun Link to this post

    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!
     
  13. Teguh
    Teguh avatar
    6 posts
    Member since:
    May 2015

    Posted 07 Jun in reply to Daniel Link to this post

    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

  14. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 07 Jun Link to this post

    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!
     
Back to Top
Kendo UI is VS 2017 Ready