Use Filter in grid with datatype DateOnly on ODataEnumerable #1460

Open
opened 2026-01-29 17:53:56 +00:00 by claunia · 0 comments
Owner

Originally created by @simonluebker on GitHub (Nov 4, 2024).

First of all i want to thank you for this awsome lib!

Describe the bug
I wanted to use the DateOnly Filter like DateOnly Query Filtering #1547 on ODataEnumerable Source. When using this approach, i get the error:

Unhandled exception rendering component: Object must implement IConvertible.
System.InvalidCastException: Object must implement IConvertible.
at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
at Radzen.QueryableExtension.GetColumnODataFilter[](RadzenDataGridColumn`1 column, Object filterValue, FilterOperator columnFilterOperator)

So i think it has to be this line of code:

May change the line to

 var value = IsEnumerable(column.FilterPropertyType) && column.FilterPropertyType != typeof(string)
                ? null : (string)Convert.ChangeType(
                    filterValue is DateTimeOffset ?
                            ((DateTimeOffset)filterValue).UtcDateTime : 
                            filterValue is DateOnly ? 
                                ((DateOnly)filterValue).ToString("yyy-MM-dd", CultureInfo.InvariantCulture) : filterValue, typeof(string), CultureInfo.InvariantCulture);

could help using all of the features already implemented.

With the use of FilterOperator=Custom , FilterValue= propertyOfDateOnly ont the DatagridColumn component and a custom implementation of Changes on the FilterTemplate where the DatePicker Component is used and the
SetCustomFilterExpressionAsync(whereExpression) got called, the filter is set right.

But there i can't use the already implemented features of the Datefilter component such as using the FilterOperator and a second value.

To Reproduce
Steps to reproduce the behavior:

  1. Using a RadzenDataGridComponent with a ODataEnumerable DataSource. Where one Property of Type is DateOnly.
  2. Set AllowFiltering to true on the DataGridComponent
  3. Use a ODataService on the OnLoadMethod of the Datagrid
  4. Define a RadzenDataGridColumn with the Property of DateOnly and set FilterMode to FilterMode.Simple
  5. Compile and open in Browser
  6. Open the Developer Tools
  7. Use the filter of the property
  8. When click on "apply" the described error occurs in the console

Expected behavior
The OData String is generated and could be used to request new data

Thank you,
best regards,
Simon

Originally created by @simonluebker on GitHub (Nov 4, 2024). First of all i want to thank you for this awsome lib! **Describe the bug** I wanted to use the DateOnly Filter like [DateOnly Query Filtering #1547](https://github.com/radzenhq/radzen-blazor/issues/1547) on ODataEnumerable Source. When using this approach, i get the error: Unhandled exception rendering component: Object must implement IConvertible. System.InvalidCastException: Object must implement IConvertible. at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) at Radzen.QueryableExtension.GetColumnODataFilter[<TItem>](RadzenDataGridColumn`1 column, Object filterValue, FilterOperator columnFilterOperator) So i think it has to be [this line of code:](https://github.com/radzenhq/radzen-blazor/blob/a397c686b8f079778e78c57f76a6be37f8eb21ea/Radzen.Blazor/QueryableExtension.cs#L656C11-L659C132) May change the line to ``` var value = IsEnumerable(column.FilterPropertyType) && column.FilterPropertyType != typeof(string) ? null : (string)Convert.ChangeType( filterValue is DateTimeOffset ? ((DateTimeOffset)filterValue).UtcDateTime : filterValue is DateOnly ? ((DateOnly)filterValue).ToString("yyy-MM-dd", CultureInfo.InvariantCulture) : filterValue, typeof(string), CultureInfo.InvariantCulture); ``` could help using all of the features already implemented. With the use of FilterOperator=Custom , FilterValue= propertyOfDateOnly ont the DatagridColumn component and a custom implementation of Changes on the FilterTemplate where the DatePicker Component is used and the `SetCustomFilterExpressionAsync(whereExpression)` got called, the filter is set right. But there i can't use the already implemented features of the Datefilter component such as using the FilterOperator and a second value. **To Reproduce** Steps to reproduce the behavior: 1. Using a RadzenDataGridComponent with a ODataEnumerable<Type> DataSource. Where one Property of Type is DateOnly. 2. Set AllowFiltering to true on the DataGridComponent 3. Use a ODataService on the OnLoadMethod of the Datagrid 4. Define a RadzenDataGridColumn with the Property of DateOnly and set FilterMode to FilterMode.Simple 5. Compile and open in Browser 6. Open the Developer Tools 7. Use the filter of the property 8. When click on "apply" the described error occurs in the console **Expected behavior** The OData String is generated and could be used to request new data Thank you, best regards, Simon
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#1460