Search code examples
c#blazorwebassemblymudblazor

MudBlazor - MudDataGrid - Default FilterDefinitions do not allow the user to modify the base filters


I'm trying to achieve a way to display a default set of filters into the MudDataGrid Component. But I would like the user be able to see the filters and have a chance to clear the pre-set filters.

Reading the documentation, there is a way to filter the information, using the property FilterDefinitions; this property is used internally to track all filters that the user made in the grid per column. So, this prop can be used to add additional filters.

The problem is that filters defined by code are not compatible with the user's filters. So, at the end the user cannot unfilter and show all the data.

I opened an issue here: https://github.com/MudBlazor/MudBlazor/issues/8370

But if anyone has an idea how to work around this scenario it would be great.


Solution

  • Here is another example to work around this problem: https://try.mudblazor.com/snippet/GucoEdPCphoVmEcu

    (You can open the console to see the internal properties)

    At the end, it's possible through the code add filters, but will be required change the filter mode to simple. It's not ideal, but works for now.

    Note:

    Seems that internally the UI creates a GUID unique per column, and through the code it cannot be possible to get this GUID, so, it can be possible to create a filter but will not be the same as it's used in the UI. (That's why the filter in code is not reflected on the filter component)