The DataGrid Enum Filter not working for OData #959

Closed
opened 2026-01-29 17:46:54 +00:00 by claunia · 2 comments
Owner

Originally created by @sabatex on GitHub (Aug 18, 2023).

A Blazor WASM project using an OData provider does not work correctly with Enum data, namely setting the OData filter as enumValue='1'. After changing the selector type from int to string, the OData filter changed to enumValue='Red' and everything worked perfectly. No testing was done for ServerSide.

Changed files:

  1. Extensions.cs
public static IEnumerable<object> EnumAsKeyValuePair(Type enumType)
{
    return Enum.GetValues(enumType).Cast<Enum>().Distinct().Select(val => new { Value = **val.ToString()**, Text = val.GetDisplayDescription() });
}
  1. QueryableExtensions.cs
                else if (PropertyAccess.IsEnum(column.FilterPropertyType) || PropertyAccess.IsNullableEnum(column.FilterPropertyType))
                    {
                        if (v != null)
                        {
                            value = **v.ToString()**;
                        }
                        if (sv != null)
                        {
                            secondValue = **sv.ToString()**;
                        }
                    }

Fork

Originally created by @sabatex on GitHub (Aug 18, 2023). A Blazor WASM project using an OData provider does not work correctly with Enum data, namely setting the OData filter as enumValue='1'. After changing the selector type from int to string, the OData filter changed to enumValue='Red' and everything worked perfectly. No testing was done for ServerSide. Changed files: 1. Extensions.cs ``` public static IEnumerable<object> EnumAsKeyValuePair(Type enumType) { return Enum.GetValues(enumType).Cast<Enum>().Distinct().Select(val => new { Value = **val.ToString()**, Text = val.GetDisplayDescription() }); } ``` 2. QueryableExtensions.cs ``` else if (PropertyAccess.IsEnum(column.FilterPropertyType) || PropertyAccess.IsNullableEnum(column.FilterPropertyType)) { if (v != null) { value = **v.ToString()**; } if (sv != null) { secondValue = **sv.ToString()**; } } ``` [Fork](https://github.com/sabatex/radzen-blazor)
Author
Owner

@enchev commented on GitHub (Aug 18, 2023):

Hey @sabatex,

You might need to check this thread: https://github.com/OData/AspNetCoreOData/issues/422 - in short you will need StringAsEnumResolver.

@enchev commented on GitHub (Aug 18, 2023): Hey @sabatex, You might need to check this thread: https://github.com/OData/AspNetCoreOData/issues/422 - in short you will need StringAsEnumResolver.
Author
Owner

@sabatex commented on GitHub (Aug 21, 2023):

I fixed the enum issue for OData query and tested for a real project. These changes do not change the default logic. After these changes, work fine with OData EDM by default after set EnumKeyAsSymbols = true. Small changes to files (Extensions, QueryableExtension) are required. My last Commit is in fork.

@sabatex commented on GitHub (Aug 21, 2023): I fixed the enum issue for OData query and tested for a real project. These changes do not change the default logic. After these changes, work fine with OData EDM by default after set EnumKeyAsSymbols = true. Small changes to files (Extensions, QueryableExtension) are required. My last Commit is in fork.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#959