Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grid Form Update number field formatted with thousand separator fix #301

Merged
merged 1 commit into from
Jul 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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