Skip to content

Commit

Permalink
Grid Form Update number field formatted with thousand separator fix (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
borisdj authored Jul 16, 2021
1 parent f51dcf1 commit c648348
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion GridBlazor/Pages/GridUpdateComponent.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
Expand Down Expand Up @@ -181,7 +182,27 @@ private void ChangeValue(ChangeEventArgs e, IGridColumn column, string typeAttr
{
try
{
var value = typeConverter.ConvertFrom(e.Value.ToString());
object value = null;
// if is number type
if (type == typeof(decimal) || type == typeof(float) || type == typeof(double) || type == typeof(byte) || type == typeof(short) || type == typeof(int) || type == typeof(long) ||
type == typeof(decimal?) || type == typeof(float?) || type == typeof(double?) || type == typeof(byte?) || type == typeof(short?) || type == typeof(int?) || type == typeof(long?))
{
string thousandSeparator = ",";
if (thousandSeparator == CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator)
{
thousandSeparator = "."; // separators are inverted compared to EN, like is in DE and some other european languages
}
string valueText = e.Value.ToString();
if (valueText.Contains(thousandSeparator))
{
valueText = valueText.Replace(thousandSeparator, ""); // removes thousands separator if exist so that parsing can be correctly done
}
value = typeConverter.ConvertFrom(valueText);
}
else
{
value = typeConverter.ConvertFrom(e.Value.ToString());
}
SetValue(value, column);
}
catch (Exception)
Expand Down

0 comments on commit c648348

Please sign in to comment.