Mudblazor Datagrid Pre-loaded filter

30 Views Asked by At

I'm using the MudDataGrid component: https://dev.mudblazor.com/components/datagrid#default-data-grid

I'm trying to add a filter as soon as the page loads, but I can't find documentation to do it.

I haven't been able to find any examples of something like this using the MudDataGrid component.

1

There are 1 best solutions below

0
Akram Al-Qaifi On

You can see (advanced filtering) in MudBlazor documentation

and chang the data in OnInitializedAsync method

protected override async Task OnInitializedAsync()
    {
        Elements = await httpClient.GetFromJsonAsync<List<Element>>("webapi/periodictable");
        _selectedItems = Elements.ToHashSet();
        _filterItems = Elements.ToHashSet();
        _filterDefinition = new FilterDefinition<Element>
        {
            FilterFunction = x => _filterItems.Contains(x)
        };
    }

The line responsible for filtering

FilterFunction = x => _filterItems.Contains(x)