Column Filter Dropdown For Enum Values

Hi. I have a bit of a problem getting my grid to filter with enum values even referencing the tutorial in the documentation https://blazor.syncfusion.com/documentation/datagrid/filtering#filter-enum-column. This is my enum:


public enum PayrollCategory

{

    [Display(Description = "Salary")]

    Salary,

    [Display(Description = "Salary Plus  B")]

    SalaryPlusB,

    [Display(Description = "B")]

    B,

}


Please help me get this working. On the dropdown I wish to display the string descriptions of the enum values.


1 Reply

NP Naveen Palanivel Syncfusion Team November 5, 2024 04:12 AM UTC

Hi À la mode Clothing Outlet

We checked your query, and it seems that you want to display the string descriptions of enum values in the dropdown filter. To achieve this, use a FilterTemplate with SfDropDownList where the Text displays the description, and the Value represents the enum for filtering. This allows the dropdown to show descriptions and filter by enum values. Please refer the code snippet and sample for more reference.

Sample : https://blazorplayground.syncfusion.com/embed/hNrJsCZJqPVRVvWk?appbar=true&editor=true&result=true&errorlist=true&theme=bootstrap5

        <GridColumn Field=@nameof(OrderData.ShipName) HeaderText="Ship Name" Width="100"></GridColumn>

        <GridColumn Field=@nameof(OrderData.Category) HeaderText="Category"  Width="130">

            <FilterTemplate>

                <SfDropDownList Placeholder="Category" ID="CategoryFilter" Value="@((string)(context as PredicateModel).Value)" DataSource="@EnumDescriptions" TValue="string" TItem="EnumDescription">

                    <DropDownListEvents TItem="EnumDescription" ValueChange="OnCategoryFilterChanged" TValue="string"></DropDownListEvents>

                    <DropDownListFieldSettings Value="Value" Text="Description"></DropDownListFieldSettings>

                </SfDropDownList>

            </FilterTemplate>

        </GridColumn>

    </GridColumns>

</SfGrid>

 

@code {

    public SfGrid<OrderData> Grid;

    public List<OrderData> GridData { get; set; }

 

    List<EnumDescription> EnumDescriptions = new List<EnumDescription>

    {

        new EnumDescription { Value = "Salary", Description = "Salary" },

        new EnumDescription { Value = "SalaryPlusB", Description = "Salary Plus B" },

        new EnumDescription { Value = "B", Description = "B" },

        new EnumDescription { Value = "All", Description = "All" }

    };


Please get back to us if you need further assistance.


Regards,

Naveen


Loader.
Up arrow icon