RadzenDataGrid does not remember the filter value #345

Closed
opened 2026-01-29 17:35:47 +00:00 by claunia · 2 comments
Owner

Originally created by @OndrejUzovic on GitHub (Mar 16, 2022).

If RadzenDataGrid.Data gets a different reference as before filter values are cleared.

E.g. consider the following code:

@page "/"

@using Radzen;
@using Radzen.Blazor;


@inject DialogService DialogService

<RadzenButton Text="Open" Click=@OnOpenClick />

<RadzenDataGrid AllowFiltering="true" FilterMode="FilterMode.Simple" Data="@MyData" TItem="Employee" ColumnWidth="300px">
    <Columns>
        <RadzenDataGridColumn TItem="Employee" Property="FirstName" Title="First Name" Width="140px" />
        <RadzenDataGridColumn TItem="Employee" Property="LastName" Title="First Name" Width="140px" />
    </Columns>
</RadzenDataGrid>


@code {

    public class Employee
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
    }

    public IEnumerable<Employee> MyData
    {
        get
        {
            yield return new Employee() { FirstName = "Peter", LastName = "Smith" };
            yield return new Employee() { FirstName = "Carl", LastName = "BlaBla" };
        }
    }

    private async Task OnOpenClick()
    {
        await DialogService.OpenAsync("Closeable from overlay Dialog", ds =>
            @<div>
                Click outside to close this Dialog
            </div>, new DialogOptions() { CloseDialogOnOverlayClick = true });
    }
}

Steps to reproduce:

  1. Set the filter value for the column First Name e.g. to "Pe" so that the data grid lists only Peter.
  2. Click the Open button.
  3. Problem: once the dialog is open the filter value is cleared and the grid lists all items.

Note:
If the MyData property returns always the same reference, e.g. List, even if cleared and felt before returning, the filtering works fine.

Please, could you check this behavior and provide a fix if it is an error?

Originally created by @OndrejUzovic on GitHub (Mar 16, 2022). If RadzenDataGrid.Data gets a different reference as before filter values are cleared. E.g. consider the following code: ``` @page "/" @using Radzen; @using Radzen.Blazor; @inject DialogService DialogService <RadzenButton Text="Open" Click=@OnOpenClick /> <RadzenDataGrid AllowFiltering="true" FilterMode="FilterMode.Simple" Data="@MyData" TItem="Employee" ColumnWidth="300px"> <Columns> <RadzenDataGridColumn TItem="Employee" Property="FirstName" Title="First Name" Width="140px" /> <RadzenDataGridColumn TItem="Employee" Property="LastName" Title="First Name" Width="140px" /> </Columns> </RadzenDataGrid> @code { public class Employee { public string FirstName { get; set; } public string LastName { get; set; } } public IEnumerable<Employee> MyData { get { yield return new Employee() { FirstName = "Peter", LastName = "Smith" }; yield return new Employee() { FirstName = "Carl", LastName = "BlaBla" }; } } private async Task OnOpenClick() { await DialogService.OpenAsync("Closeable from overlay Dialog", ds => @<div> Click outside to close this Dialog </div>, new DialogOptions() { CloseDialogOnOverlayClick = true }); } } ``` Steps to reproduce: 1. Set the filter value for the column First Name e.g. to "Pe" so that the data grid lists only Peter. 2. Click the Open button. 3. Problem: once the dialog is open the filter value is cleared and the grid lists all items. Note: If the MyData property returns always the same reference, e.g. List<Employee>, even if cleared and felt before returning, the filtering works fine. Please, could you check this behavior and provide a fix if it is an error?
Author
Owner

@ferrarinim commented on GitHub (Mar 23, 2022):

We have the same issue.
Did you find any solution?

@ferrarinim commented on GitHub (Mar 23, 2022): We have the same issue. Did you find any solution?
Author
Owner

@enchev commented on GitHub (Apr 11, 2022):

This is expected behavior - filters will be cleared on Data change. You can use IList instead to avoid such problems.

@enchev commented on GitHub (Apr 11, 2022): This is expected behavior - filters will be cleared on Data change. You can use IList instead to avoid such problems.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#345