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

The DataGrid Enum Filter not working for OData #1118

Closed
sabatex opened this issue Aug 18, 2023 · 2 comments
Closed

The DataGrid Enum Filter not working for OData #1118

sabatex opened this issue Aug 18, 2023 · 2 comments

Comments

@sabatex
Copy link

sabatex commented 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

@enchev
Copy link
Collaborator

enchev commented Aug 18, 2023

Hey @sabatex,

You might need to check this thread: OData/AspNetCoreOData#422 - in short you will need StringAsEnumResolver.

@enchev enchev closed this as completed Aug 18, 2023
@sabatex
Copy link
Author

sabatex commented 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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants