RadzenDatagridColumn filter cannot be cleared after setting FilterValue #1507

Closed
opened 2026-01-29 17:54:38 +00:00 by claunia · 5 comments
Owner

Originally created by @tmyllymaki on GitHub (Nov 29, 2024).

Describe the bug
I'm setting an initial value on a RadzenDatagridColumn<T>.FilterValue as so:

foreach (var (key, filterValue) in GridFilters)
{
    if (filterValue is null) continue;
    var column = _dataGrid.ColumnsCollection.FirstOrDefault(c => c.Title == key);
    if (column is null) continue;
    column.FilterValue = filterValue;
}
await _dataGrid.Reload();

After setting the FilterValue you can't clear the filter as the GetFilterValue() always fallbacks to the initial FilterValue which is not modified:

public object GetFilterValue()
{
    return filterValue ?? FilterValue;
}

You can circumvent the issue by using the SetFilterValueAsync.

Expected behavior
The FilterValue should update when the component is updated or the property should be modified or removed.

Desktop (please complete the following information):

  • Version 5.6.9
Originally created by @tmyllymaki on GitHub (Nov 29, 2024). <!-- IMPORTANT: Read this first!!! 1. If you own a Radzen Professional or Еnterprise subscription you can report your issue or ask us a question via email at info@radzen.com. Radzen staff will reply within 24 hours (Professional) or 16 hours (Enterprise) 2. The Radzen staff guarantees a response to issues in this repo only to paid subscribers. 3. If you have a HOW TO question start a new forum thread in the Radzen Community forum: https://forum.radzen.com. Radzen staff will close issues that are HOWTO questions. 4. Please adhere to the issue template. Specify all the steps required to reproduce the issue or link a project which reproduces it easily (without requiring extra steps such as restoring a database). --> **Describe the bug** I'm setting an initial value on a `RadzenDatagridColumn<T>.FilterValue` as so: ```csharp foreach (var (key, filterValue) in GridFilters) { if (filterValue is null) continue; var column = _dataGrid.ColumnsCollection.FirstOrDefault(c => c.Title == key); if (column is null) continue; column.FilterValue = filterValue; } await _dataGrid.Reload(); ``` After setting the `FilterValue` you can't clear the filter as the `GetFilterValue()` always fallbacks to the initial `FilterValue` which is not modified: ```csharp public object GetFilterValue() { return filterValue ?? FilterValue; } ``` You can circumvent the issue by using the `SetFilterValueAsync`. **Expected behavior** The `FilterValue` should update when the component is updated or the property should be modified or removed. **Desktop (please complete the following information):** - Version 5.6.9
Author
Owner

@enchev commented on GitHub (Nov 29, 2024):

This demo is using exactly the same approach and the value can be cleared:
https://blazor.radzen.com/datagrid-filter-api?theme=material3

@enchev commented on GitHub (Nov 29, 2024): This demo is using exactly the same approach and the value can be cleared: https://blazor.radzen.com/datagrid-filter-api?theme=material3
Author
Owner

@tmyllymaki commented on GitHub (Nov 29, 2024):

I'm sorry but it's not. It's using the the method SetFilterValue. If you change it to the property FilterValue it can't be cleared.

@tmyllymaki commented on GitHub (Nov 29, 2024): I'm sorry but it's not. It's using the the method `SetFilterValue`. If you change it to the property `FilterValue` it can't be cleared.
Author
Owner

@enchev commented on GitHub (Nov 29, 2024):

FilterValue should not be used since this is what will be restored when you execute StateHasChanged().

@enchev commented on GitHub (Nov 29, 2024): FilterValue should not be used since this is what will be restored when you execute StateHasChanged().
Author
Owner

@tmyllymaki commented on GitHub (Nov 29, 2024):

Yeah I kind of had to figure it out myself. Maybe add a warning or something on the property.

@tmyllymaki commented on GitHub (Nov 29, 2024): Yeah I kind of had to figure it out myself. Maybe add a warning or something on the property.
Author
Owner

@enchev commented on GitHub (Nov 29, 2024):

The warning is added directly by Blazor framework and Visual Studio when you build the project - it's not something specific to Radzen.Blazor compoents. Public parameters should not be set using code.

@enchev commented on GitHub (Nov 29, 2024): The warning is added directly by Blazor framework and Visual Studio when you build the project - it's not something specific to Radzen.Blazor compoents. Public parameters should not be set using code.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#1507