DataGrid loses filter on data change

I have a RadzenDataGrid component where I apply various filters, but when the data changes the filters get reset. I found this GitHub issue with the exact same problem. I tried the suggested fix of changing from IEnumerable to IList, but this doesn't work:

Any other ideas?

Thanks.

We cannot provide any comments until we have actual code that reproduces the problem. You can use our demos to replicate your case.

Try this, add a filter on the grid and then click the "Change Data" button. The filter gets reset.

<RadzenButton Text="Change Data" Click=@OnChangeDataClick />

<RadzenDataGrid AllowFiltering="true" FilterMode="FilterMode.Simple" Data="@data" 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 {
    private IList<Employee> data;

    protected override void OnInitialized()
    {
        SetData();
    }    

    private void OnChangeDataClick()
    {
        SetData();
    }

    private void SetData()
    {
        data = new List<Employee>() { new Employee() { FirstName = "Peter", LastName = "Smith" }, new Employee() { FirstName = "Carl", LastName = "BlaBla" } };
    }

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

You might need to use LoadData binding instead in such case:

@using System.Linq.Dynamic.Core

<RadzenButton Text="Change Data" Click=@OnChangeDataClick />

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


@code {
    private IList<Employee> employees = new List<Employee>() { new Employee() { FirstName = "Peter", LastName = "Smith" }, new Employee() { FirstName = "Carl", LastName = "BlaBla" } };
    private IList<Employee> data;
    private int count;

    RadzenDataGrid<Employee> grid;

    private void OnChangeDataClick()
    {
        SetData();
        grid.Reload();
    }

    private void SetData()
    {
        data = employees;
    }

    private void LoadData(LoadDataArgs args)
    {
        var query = employees.AsQueryable();

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

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

        count = query.Count();

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

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