decimals separator, inline editing

6 posts, 1 answers
  1. Jacob
    Jacob avatar
    45 posts
    Member since:
    Sep 2014

    Posted 01 Apr 2015 Link to this post

    Hi,

    I have a problem with decimal separators when doing inline editing.
    Right now I have a solution that works, but I need more than two digits after the decimal separator:

    The model:
    [DataType("number")]
    public double Percent
    {
        get { return (double)Math.Round(source.Percent, 5); }
        set { source.Percent = (decimal)value; }
    }

    The view:
    .Columns(columns =>
    {
        columns.Bound(c => c.Percent).Title(Resource.Percent).Format("{0:n5}");

    Setting the culture:
    var c = '@System.Globalization.CultureInfo.CurrentCulture.ToString()'
    kendo.culture(c);

    The DataType=number, in the model, formats the inline input box the correct way.
    The "Format("{0:n5}")", in the view, formats the number correctly in the grid.
    There is no problems when updating the model (model-state is valid), but I need higher precision.

    thanks.
  2. Rosen
    Admin
    Rosen avatar
    3253 posts

    Posted 03 Apr 2015 Link to this post

    Hello Jacob,

    I'm afraid I'm not sure what is the exact issue you are facing. Is it that the NumericTextBox widget does not show the decimals during editing? If this is the case you may need to change the editor widget configuration, for example:

    @(Html.Kendo().NumericTextBoxFor(m => m)
           .HtmlAttributes(new { style = "width:100%" })
           .Decimals(5)
    )


    Regards,
    Rosen
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  3. Jacob
    Jacob avatar
    45 posts
    Member since:
    Sep 2014

    Posted 15 Apr 2015 in reply to Rosen Link to this post

    Hi Rosen,

    No, the width is fine.The problem is that it won't show more than two digits after the decimal separator.

    The solution I'm talking about (the question) does only show two digits, i need five.

    Thanks.

  4. Rosen
    Admin
    Rosen avatar
    3253 posts

    Posted 16 Apr 2015 Link to this post

    Hello Jacob,

    The suggestion I was trying to make is to use the Decimals method of the widget to increment the decimals. Did this not work?

    Regards,
    Rosen
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  5. Jacob
    Jacob avatar
    45 posts
    Member since:
    Sep 2014

    Posted 12 May 2015 in reply to Rosen Link to this post

    Hi Rosen,

     I don't know what it is I should test - Decimals() is not a valid method to Columns ??

    I believe you miss the point here (or I'm not able to explain it):

    * If I don't add the DataType attribute to the model ([DataType("number")]), the decimal separator is not following the culture settings on editing (the decimal separator is following the English culture only, but only on inline edit).

    * If I use the DataType attribute, I can't select a type, that gives me more than two decimals.

    Thanks.

  6. Answer
    Rosen
    Admin
    Rosen avatar
    3253 posts

    Posted 13 May 2015 Link to this post

    Hello Jacob,

    The Decimals is setting of the NumericTextBox widget which is used as an EditorTemplate. This is where the change should be made.

    Regarding the DataType attributes - as you know this attribute purpose is to instruct the ASP.NET MVC framework which EditorTemplate should be instantiated for the decorated property when set in edit mode. Thus, setting the DataType to number usually will instantiate the EditorTemplate named Number.cshtml. This is where you will need to apply the required changes to the editor widget.

    Information on using EditorTemplate in the context of our Grid widget can be found here. For general information on Editor Templates see Brad Wilson's blog series on ASP.NET MVC 2 Templates.

    If you continue to experience difficulties please provide a small runnable sample which demonstrates the issue. 

    Regards,
    Rosen
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top