radzenhq / radzen-blazor

Radzen Blazor is a set of 90+ free native Blazor UI components packed with DataGrid, Scheduler, Charts and robust theming including Material design and FluentUI.
https://www.radzen.com
MIT License
3.52k stars 785 forks source link

RadzenDataGrid data filtering Int32 type column raizes an exception "System.FormatException: Input string was not in a correct format" #511

Closed harry-flw closed 2 years ago

harry-flw commented 2 years ago

RadzenDataGrid data filtering Int32 type column raizes an exception "System.FormatException: Input string was not in a correct format"

Describe the bug Entering the number "-1" in the field in the filter dialog results in a fatal error.

To Reproduce Steps to reproduce the behavior:

  1. Open the page where is the RadzenDataGrid component. The RadzenDataGrid component must have an Int32 column and the option AllowFiltering must be set to "true"
  2. Click on the filter icon for the Int32 column.
  3. In the filtering dialog that appears, enter the value -1. It's important do not press arrows, just type -1
  4. See error [2022-07-05T07:18:34.439Z] Error: System.FormatException: Input string was not in a correct format. at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, TypeCode type) at System.Number.ParseInt32(ReadOnlySpan1 value, NumberStyles styles, NumberFormatInfo info) at System.String.System.IConvertible.ToInt32(IFormatProvider provider) at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) at Radzen.Blazor.RadzenDataGrid1.<>c__DisplayClass48_1.b__3(ChangeEventArgs args) --- End of stack trace from previous location --- at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task) at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)

Expected behavior If user can enter -1 without any errors by arrows in the field - user must have a possibility to enter -1 from keyboard without any errors.

Screenshots This is an image

This is an image

Desktop (please complete the following information):

enchev commented 2 years ago

I'm unable to reproduce such exception on our demos: image

harry-flw commented 2 years ago

Good day, Vladimir.

Thank you for your response.

My settings are:

<RadzenDataGrid AllowFiltering="true" AllowPaging="true" PageSize="14" AllowSorting="true" EditMode="DataGridEditMode.Single">

And I can reproduce this bug anytime.

harry-flw commented 2 years ago

Open your demo here: https://blazor.radzen.com/datagrid-enum-filter and do the same things for the ID column. Open developer console and you will see the same bug.

harry-flw commented 2 years ago

As the exception said the problem is in the DrawNumericFilter method. As I understand it's about this line:

column.SetFilterValue(!string.IsNullOrWhiteSpace(str) ? Convert.ChangeType((object) str, Nullable.GetUnderlyingType(type)) : (object) null, isFirst);

harry-flw commented 2 years ago

alt text

harry-flw commented 2 years ago

Dear Vladimir,

please inform me if I need to reopen this bug.

Thank you.