RadzenDropDown in DataGrid using Enums

I want to filter my Enum columm in my datagrid using a DropDown.
I've got it almost working using the example from https://blazor.radzen.com/datagrid-filter-template

My code:

<RadzenGridColumn TItem="MDGR.Models.Entities.Master.Client" Property="DatabaseStatus" Title="Database status">
    <FilterTemplate>
        <RadzenDropDown @bind-Value="@currentStatus" TextProperty="Text" ValueProperty="Value" Style="width:100%"
                        Data="@(getStatusses)" SelectedItem="@getStatusses[0]" />
    </FilterTemplate>
</RadzenGridColumn>
getStatusses = Enum.GetValues(typeof(Status)).Cast<Status>()
                   .Select(t => new SelectListItem { Text = $"{t}", Value = t }).ToList();
getStatusses.Insert(0, new SelectListItem { Text = "All", Value = -1 });

When the page is loaded, this first enum value is selected and thus is my datagrid filtered.
I don't want that, I want the DropDown to select the added value All, -1

How to do that?
Do I need to add All to my Enum? I prefer not to.

1 Like

The Radzen dropdown will select its Value property (you are setting it to currentStatus).

I've got it working now.
I needed to make currentStatus an int instead of Status and cast Value to int too.

For future reference:

My Data of DataGrid:

Data="@getClients.Where(e => currentStatus < 0 || (int)e.DatabaseStatus == currentStatus)"
protected int currentStatus = -1;

public async System.Threading.Tasks.Task Load(){
            getStatusses = Enum.GetValues(typeof(Status)).Cast<Status>()
                .Select(t => new SelectListItem { Text = $"{t}", Value = (int)t }).ToList();
            getStatusses.Insert(0, new SelectListItem { Text = "All", Value = -1 });
}
2 Likes

I had troubles to implement like so since the load method is not working for me. I don't know which type getStatusses is and where to trigger the method. it seems as if getStatusses should be a closs property I have to specivy the type now and it doesn't even finish the method when I try to class it var.

I actually get this error:

Argument 2: cannot convert from '<anonymous type: string Text, int Value>' to '<>f__AnonymousType0<string, int>'

Any idea what is going on and how I can fix this?