RadzenDataGrid FilterOperator changing to Contains on clear even when restricted #1697

Closed
opened 2026-01-29 17:57:24 +00:00 by claunia · 0 comments
Owner

Originally created by @Conor-Petford on GitHub (Apr 1, 2025).

In a DataGrid when using FilterValueTemplate contained specifically a RadzenTextBox, the FilterOperator is set to FilterOperator.Equals for the column and the FilterOperators only contains the Equals and NotEquals operators. However when the 'Clear' option is selected from the Filter Operator drop-down, the FilterOperator is set to Contains.

To Reproduce use the following code from DataGrid Column FilterValueTemplate that has been edited below:

<RadzenDataGrid @ref="grid" Data=@employees FilterMode="FilterMode.SimpleWithMenu" AllowFiltering="true" AllowPaging="true" AllowSorting="true"
ColumnWidth="300px" Filter="@OnFilter" FilterCleared="OnFilterCleared" TItem="Employee">
    <Columns>
        <RadzenDataGridColumn Property="@nameof(Employee.TitleOfCourtesy)" Title="Title Of Courtesy" FilterValue="@currentTOC" FilterOperator="FilterOperator.Equals" FilterOperators="@(new FilterOperator[]{ FilterOperator.Equals, FilterOperator.NotEquals})">
            <FilterValueTemplate>
                <RadzenTextBox @bind-Value="@currentTOC" Style="width: 100%"/>
            </FilterValueTemplate>
        </RadzenDataGridColumn>
    </Columns>
</RadzenDataGrid>


@code {
    RadzenDataGrid<Employee> grid;
    string? currentTOC;


    public class Employee
    {
        public string TitleOfCourtesy { get; set; }
    }

    bool IsNullOrEmpty(FilterOperator? value)
    {
        return value == FilterOperator.IsEmpty || value == FilterOperator.IsNotEmpty || value == FilterOperator.IsNull || value == FilterOperator.IsNotNull;
    }

    void ClearCustomFilters(DataGridColumnFilterEventArgs<Employee> args)
    {
        if (args.Column.Property == "TitleOfCourtesy")
        {
            currentTOC = null;
        }
    }

    void OnFilter(DataGridColumnFilterEventArgs<Employee> args)
    {
        if (IsNullOrEmpty(args.Column.GetFilterOperator()))
        {
            ClearCustomFilters(args);
        }
    }

    void OnFilterCleared(DataGridColumnFilterEventArgs<Employee> args)
    {
        ClearCustomFilters(args);
    }

    IEnumerable<Employee> employees; 

    protected override async Task OnInitializedAsync()
    {
        employees = await Task.FromResult(Enumerable.Range(0, 10).Select(i =>
            new Employee
            {
                TitleOfCourtesy = i < 5 ? "Mr" : "Ms",
            }).AsQueryable());
    }
}

Expected Behavior - For the FilterOperators drop down to return to Equals instead of the current behavior below:

Image

Image

OS - Windows
Browser - Chrome
Radzen Version - 6.4.0

Originally created by @Conor-Petford on GitHub (Apr 1, 2025). In a DataGrid when using FilterValueTemplate contained specifically a RadzenTextBox, the FilterOperator is set to FilterOperator.Equals for the column and the FilterOperators only contains the Equals and NotEquals operators. However when the 'Clear' option is selected from the Filter Operator drop-down, the FilterOperator is set to Contains. To Reproduce use the following code from [DataGrid Column FilterValueTemplate](https://blazor.radzen.com/datagrid-filtervalue-template?theme=material3) that has been edited below: ``` <RadzenDataGrid @ref="grid" Data=@employees FilterMode="FilterMode.SimpleWithMenu" AllowFiltering="true" AllowPaging="true" AllowSorting="true" ColumnWidth="300px" Filter="@OnFilter" FilterCleared="OnFilterCleared" TItem="Employee"> <Columns> <RadzenDataGridColumn Property="@nameof(Employee.TitleOfCourtesy)" Title="Title Of Courtesy" FilterValue="@currentTOC" FilterOperator="FilterOperator.Equals" FilterOperators="@(new FilterOperator[]{ FilterOperator.Equals, FilterOperator.NotEquals})"> <FilterValueTemplate> <RadzenTextBox @bind-Value="@currentTOC" Style="width: 100%"/> </FilterValueTemplate> </RadzenDataGridColumn> </Columns> </RadzenDataGrid> @code { RadzenDataGrid<Employee> grid; string? currentTOC; public class Employee { public string TitleOfCourtesy { get; set; } } bool IsNullOrEmpty(FilterOperator? value) { return value == FilterOperator.IsEmpty || value == FilterOperator.IsNotEmpty || value == FilterOperator.IsNull || value == FilterOperator.IsNotNull; } void ClearCustomFilters(DataGridColumnFilterEventArgs<Employee> args) { if (args.Column.Property == "TitleOfCourtesy") { currentTOC = null; } } void OnFilter(DataGridColumnFilterEventArgs<Employee> args) { if (IsNullOrEmpty(args.Column.GetFilterOperator())) { ClearCustomFilters(args); } } void OnFilterCleared(DataGridColumnFilterEventArgs<Employee> args) { ClearCustomFilters(args); } IEnumerable<Employee> employees; protected override async Task OnInitializedAsync() { employees = await Task.FromResult(Enumerable.Range(0, 10).Select(i => new Employee { TitleOfCourtesy = i < 5 ? "Mr" : "Ms", }).AsQueryable()); } } ``` Expected Behavior - For the FilterOperators drop down to return to Equals instead of the current behavior below: ![Image](https://github.com/user-attachments/assets/384026eb-8ef6-40d2-9215-c741cb84a0c1) ![Image](https://github.com/user-attachments/assets/c6d86807-9ba9-4dba-a489-682ce5009d01) OS - Windows Browser - Chrome Radzen Version - 6.4.0
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#1697