DataGridSettings aren't loaded if grid is empty

I have a DataGrid with bound LoadData event. I want to Save/Load DataGridSettings on a button click. It works fine except the case when loading settings in a grid with applied filter that shows no data. Please see modified Blazor DataGrid save/load settings with LoadData example and screen recording for details.

@using Radzen
@using RadzenBlazorDemos.Data
@using RadzenBlazorDemos.Models.Northwind
@using Microsoft.EntityFrameworkCore
@using RadzenBlazorDemos.Services
@using Microsoft.JSInterop
@using System.Text.Json
@using System.Linq.Dynamic.Core

@inject IJSRuntime JSRuntime
@inject NavigationManager NavigationManager

@inherits DbContextPage

<p>This example shows how to save/load DataGrid state using Settings property when binding using LoadData event.</p>
<p>The state includes current page index, page size, groups and columns filter, sort, order, width and visibility.</p>
<RadzenButton Click="@(args => Settings = null)" Text="Clear saved settings" Style="margin-bottom: 16px" />
<RadzenButton Click="SaveStateAsync" Text="Save settings" Style="margin-bottom: 16px" />
<RadzenButton Click="LoadStateAsync" Text="Load saved settings" Style="margin-bottom: 16px" />
<RadzenButton Click="@(args => NavigationManager.NavigateTo("/datagrid-save-settings", true))" Text="Reload" Style="margin-bottom: 16px" />
<RadzenDataGrid @ref=grid @bind-Settings="@Settings" AllowFiltering="true" AllowColumnPicking="true" AllowGrouping="true" AllowPaging="true" PageSize="4"
                AllowSorting="true" AllowMultiColumnSorting="true" ShowMultiColumnSortingIndex="true" 
                AllowColumnResize="true" AllowColumnReorder="true" ColumnWidth="200px"
                FilterPopupRenderMode="PopupRenderMode.OnDemand" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive" 
                Data="@employees" IsLoading=@isLoading Count="@count" LoadData=@LoadData TItem="Employee">
        <RadzenDataGridColumn TItem="Employee" Property="Photo" Title="Employee" Sortable="false" Filterable="false">
            <Template Context="data">
                <RadzenImage Path="@data.Photo" style="width: 40px; height: 40px; border-radius: 8px; margin-right: 8px;" />
                @data.FirstName @data.LastName
        <RadzenDataGridColumn TItem="Employee" Property="Title" Title="Title" />
        <RadzenDataGridColumn TItem="Employee" Property="EmployeeID" Title="Employee ID" />
        <RadzenDataGridColumn TItem="Employee" Property="HireDate" Title="Hire Date" FormatString="{0:d}" />
        <RadzenDataGridColumn TItem="Employee" Property="City" Title="City" />
        <RadzenDataGridColumn TItem="Employee" Property="Country" Title="Country" />

<EventConsole @ref=@console />

@code {
    RadzenDataGrid<Employee> grid;
    IEnumerable<Employee> employees;
    EventConsole console;

    int count;
    bool isLoading = false;
    async Task LoadData(LoadDataArgs args)
        isLoading = true;

        await Task.Yield();

        var query = dbContext.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();

        employees = await Task.FromResult(query.Skip(args.Skip.Value).Take(args.Top.Value).ToList());

        isLoading = false;

    public DataGridSettings Settings { get; set; }

    private async Task LoadStateAsync()
        var result = await JSRuntime.InvokeAsync<string>("window.localStorage.getItem", "SettingsLoadData");
        if (!string.IsNullOrEmpty(result))
            Settings = JsonSerializer.Deserialize<DataGridSettings>(result);

    private async Task SaveStateAsync()
        await JSRuntime.InvokeVoidAsync("eval", $@"window.localStorage.setItem('SettingsLoadData', '{JsonSerializer.Serialize<DataGridSettings>(Settings)}')");

Load Saved Settings Problem

According to the gif you've not pressed Save settings button after filtering by Title.

I don't want to save settings after filtering by Title. My gif demonstrates the following scenario:

  1. Apply a filter that produces some result rows
  2. Save the applied filter in settings
  3. Clear the filter
  4. Load the settings saved in step 2 to show that it works as expected and produces the same result as in step 1
  5. Apply a filter that produces no result rows
  6. Load the settings saved in step 2. Expected result: the same as in step 4. Actual result: no rows are shown.

You can attach the source code of Radzen.Blazor to your project to debug your case.

Debugging the source code showed that the problem is caused by this check. If I delete it, it works as expected.

Try to change the code to skip <= View.Count() and let me know if it works.

The suggested change makes it work when the page number saved in settings is 1. When I save settings with page number > 1, I get the same empty result as in my demonstration. However, in my real application, I don't need to save the page number in settings, so the provided solution is acceptable.

Feel free to submit pull request with better solution that will handle all cases.

I don't need to handle all the cases right now. Should I make a pull request with the current change suggested by you?

I already submitted this change.

Ok, thank you very much!