How to clear Custom Filter on DataGrid Reset

When using a FilterTemplate in DataGrid, calling grid.Reset does not clear the custom filter.
The Demo will show this.

I tried clearing the selectedTitles IEnumerable in the Reset method, but that throws a DbContext threading error

Not sure what's that error. Can you post more info?

I have yet to determine if this is just an issue with my own async processes.
Paging and Reset works fine without using the Custom Filter.
Once the Custom Filter is in place, I get async threading issues on the DbContext.

It breaks on:

await grid.FirstPage(true);

Full code:

Video: https://imgur.com/a/HBaH8i5

<RadzenButton Text="Reset" Click="@Reset" Style="margin-bottom: 20px;" />
<RadzenDataGrid @ref="grid" IsLoading=@isLoading Count="@count" Data="@staffResults" LoadData="@LoadData" AllowFiltering="true"
                FilterMode="FilterMode.Advanced" AllowSorting="true" AllowPaging="true" PageSize="10" TItem="Staff" ColumnWidth="200px">
    <Columns>
        <RadzenDataGridColumn TItem="Staff" Property="FirstName" Title="First Name" Width="100px" />
        <RadzenDataGridColumn TItem="Staff" Property="GroupSetting.GroupName" Title="Primary Group" 
            Type="typeof(IEnumerable<string>)" FilterValue="@selectedGroups" FilterOperator="FilterOperator.Contains" Width="140px">
            <FilterTemplate>
                <label class="rz-grid-filter-label">Filter</label>
                <RadzenDropDown @bind-Value=@selectedGroups Style="width:300px" ValueProperty="GroupName" TextProperty="GroupName"
                    Change=@OnSelectedGroupsChange Data="@(groups)" AllowClear="true" Multiple="true" />
            </FilterTemplate>
        </RadzenDataGridColumn>
    </Columns>
</RadzenDataGrid>

@code {
    private RadzenDataGrid<Staff> grid;
    private int count;
    private IEnumerable<Staff> staffResults;
    private bool isLoading = false;

    private IEnumerable<GroupSetting> groups;
    private IEnumerable<string> selectedGroups;

    protected override async Task OnInitializedAsync()
    {
        groups = await UnitOfWork.GroupSetting.GetAllAsync(s => s.GroupStatus == true, s => s.OrderBy(x => x.GroupName));
    }

    private void OnSelectedGroupsChange(object value)
    {
        if (selectedGroups != null && !selectedGroups.Any())
        {
            selectedGroups = null;  
        }
    }

    private async Task Reset()
    {
        selectedGroups = null;
        grid.Reset(true);
        await grid.FirstPage(true);
    }

    private async Task LoadData(LoadDataArgs args)
    {
        isLoading = true;

        await Task.Yield();

        staffResults = await UnitOfWork.Staff.GetAllAsync(s => s.AccessLevel == true,
                                                            s => s.OrderBy(x => x.LastName),
                                                        includeProperties: "GroupSetting");

        var query = staffResults.AsQueryable();

        if (!string.IsNullOrEmpty(args.Filter))
        {
            query = query.Where(args.Filter);
        }

        if (!string.IsNullOrEmpty(args.OrderBy))
        {
            query = query.OrderBy(args.OrderBy);
        }

        count = query.Count();

        staffResults = query.Skip(args.Skip.Value).Take(args.Top.Value).ToList();

        isLoading = false;
    }

}

Ok the error was due to my own async issues, you can disregard that.

However, even though setting the IEnumerable to null does clear the filters correctly, the Label does not clear and still shows the last selection

1 Like

Yes. I see this same issue. I see the dropdown control still showing the previously selected value.
I have even tried to set the filter to null using:
grid.ColumnsCollection.First(c => c.Property == "PropertyName").FilterValue = null;