Culture problems when editing numeric values inside grid cell

4 posts, 0 answers
  1. Daniel
    Daniel avatar
    9 posts
    Member since:
    Aug 2016

    Posted 16 Jan 2020 Link to this post

    I'm using Telerik for ASP.NET Core Wrappers, setting culture and format for column.

    Display format is correct according to culture, the problem is that when I edit the field, format is always in English culture, with dot separator for decimal. When I save it, it considers the culture and ignore the dot because it is not the culture decimal separator.

    Images:

    DisplayMode.PNG - Ok

    EditMode.PNG - Using dot as decimal separator - Not Ok

    DisplayModeAfterChange - 20.6 is recognized as 206

     

    Culture:

    <script type="text/javascript">
        kendo.culture("@System.Globalization.CultureInfo.CurrentCulture.ToString()");
    </script>

     

    Column:

    columns.Bound(p => p.PrecoDeVenda).Width(120).Format("{0: R'$' #,###,##0.##}")

     

    DataSource:

    .DataSource(dataSource => dataSource
                .WebApi()
                .Model(model =>
                {
                      ...
                })
                .Batch(true)
                .Culture(System.Globalization.CultureInfo.CurrentCulture.ToString())
                ...
            )

     

    DataSource:

    columns.Bound(p => p.PrecoDeVenda).Width(120).Format("{0: R'$' #,###,##0.##}")
  2. Daniel
    Daniel avatar
    9 posts
    Member since:
    Aug 2016

    Posted 16 Jan 2020 Link to this post

    I am using Telerik version 2020.1.114 and tried with [DataType("Number")] on the column but no change.
  3. Georgi
    Admin
    Georgi avatar
    698 posts

    Posted 20 Jan 2020 Link to this post

    Hi Daniel,

    I noticed that you have submitted the same query in a ticket, as I have already answered in the ticket, I will post the reply here as well in case someone else has the same question.

    =========================

    The default editor of the grid is a plain input element. Thus, formatting is not supported with it. If you need to format the value in edit mode, you will have to create a custom editor template which contains a NumericTextBox with a specified format setting.

    In other words, in the ~/Views/Shared/EditorTemplates folder, add a view with a name "Number.cshtml" and within that view create a NumericTextBox as follows:

          @(Html.Kendo().NumericTextBoxFor(x=>)
                .Format("c2" ) // set format here
          )

    Please note that you will also have to decorate the field of the model with the UIHint attribute to specify that this view is its editor.

    e.g.

    [UIHint("Number")]

    Regards,
    Georgi
    Progress Telerik

    Get quickly onboarded and successful with your Telerik UI for ASP.NET MVC with the dedicated Virtual Classroom technical training, available to all active customers.
  4. Daniel
    Daniel avatar
    9 posts
    Member since:
    Aug 2016

    Posted 20 Jan 2020 in reply to Georgi Link to this post

    Hi, Georgi,

    Yes, it is already solved, thank you.

    For anyone having the same problem, the code is missing this at the start of the cshtml file:

    @model double?

     

    And missing one x:

    @(Html.Kendo().NumericTextBoxFor(x=> x)
                .Format("c2" ) // set format here       )

     

     

Back to Top