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

decimal separator problem in grid column

1 Answer 279 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tomas Rudolf
Top achievements
Rank 1
Tomas Rudolf asked on 15 Oct 2012, 09:45 PM

I have application, which uses cs-CZ globalization. Everything is OK, but Kendo grid is not. Problem is in decimal separator in decimal columns. Grid calls my Action method and every sends "." instead of "," as decimal separator. There is my Action method:

 ActionResult UpdateProjectEmployee([DataSourceRequest] DataSourceRequest request, Models.ProjectEmployee employee )
 { 
    if (employee != null & ModelState.IsValid)
    {
      ...

  
My Action method fails (ModelState.IsValid is false), because MVC is not able to create my model, beacuse of decimal separator is "." and Convert methods expect "," because I use cs-CZ globalization. I thing, it is a bug in kendo Grid! I resolved this by using FormCollection instead of my model:
 
 ActionResult UpdateProjectEmployee([DataSourceRequest] DataSourceRequest request, FormCollection data )
 { 
    CultureInfo ci = new CultureInfo("en-US");
    Models.ProjectEmployee employee = new Models.ProjectEmployee();
    employee.TotalHours = Convert.ToDecimal( data["TotalHours"], ci );
 ...
 

But it is not so nice :(
 
   

1 Answer, 1 is accepted

Sort by
0
Dmitry
Top achievements
Rank 2
answered on 30 Nov 2012, 10:16 AM
Tomas,

I have the same problem and I've started support ticket.

It's a problem of the Grid, that has to be fixed in the next internal builds.

---%<------------------------------------------
Until then you should use the following workaround - format all numbers before the grid sends the data to the controller with the correct culture using kendo.toString method. Please check the example below:

Read and Update actions definition:
.Create(update => update.Action("Indicators_Add", "Home").Data("convert"))
.Read(read => read.Action("Indicators_Read", "Home"))
.Update(update => update.Action("Indicators_Update", "Home").Data("convert"))

Convert function:
function convert(data) {
    for (var property in data) {
        var value = data[property];
        if (typeof value === "number") {
            if (value % 1 == 0) {
                data[property] = value.toString();
            }
            else {
                data[property] = kendo.toString(value, "n");
            }
        }
    }
}
-->%---------------------------------------------------
Tags
Grid
Asked by
Tomas Rudolf
Top achievements
Rank 1
Answers by
Dmitry
Top achievements
Rank 2
Share this question
or