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

Culture problems when editing numeric values inside grid cell

3 Answers 599 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 16 Jan 2020, 05:19 PM

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.##}")

3 Answers, 1 is accepted

Sort by
0
Daniel
Top achievements
Rank 1
answered on 16 Jan 2020, 05:20 PM
I am using Telerik version 2020.1.114 and tried with [DataType("Number")] on the column but no change.
0
Georgi
Telerik team
answered on 20 Jan 2020, 12:08 PM

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.
0
Daniel
Top achievements
Rank 1
answered on 20 Jan 2020, 05:47 PM

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       )

 

 

Tags
Grid
Asked by
Daniel
Top achievements
Rank 1
Answers by
Daniel
Top achievements
Rank 1
Georgi
Telerik team
Share this question
or