DataGrid: saving settings + virtualization + sorting a column = System.ArgumentNullException #663

Closed
opened 2026-01-29 17:41:12 +00:00 by claunia · 1 comment
Owner

Originally created by @Alex55040 on GitHub (Dec 6, 2022).

  1. Use the following example as a base
    https://blazor.radzen.com/datagrid-save-settings

The issue appears even without saving and loading the settings - just using only the bound settings property.

  1. Add virtualization as described here
    https://blazor.radzen.com/datagrid-virtualization-loaddata

  2. Now try to order some column - you'll get the System.ArgumentNullException inside the browser (MS Edge):

Error: System.ArgumentNullException: Value cannot be null. (Parameter 'source')
at Microsoft.AspNetCore.Components.Web.Virtualization.Virtualize`1.BuildRenderTree(RenderTreeBuilder builder)
at Microsoft.AspNetCore.Components.ComponentBase.<.ctor>b__6_0(RenderTreeBuilder builder)
at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException)

  1. Then set AllowVirtualization to "false", or remove @bind-Settings="@Settings" - the exception is gone. Filtering doesn't throw the exception.
Originally created by @Alex55040 on GitHub (Dec 6, 2022). 1. Use the following example as a base https://blazor.radzen.com/datagrid-save-settings The issue appears even without saving and loading the settings - just using only the bound settings property. 2. Add virtualization as described here https://blazor.radzen.com/datagrid-virtualization-loaddata 3. Now try to order some column - you'll get the System.ArgumentNullException inside the browser (MS Edge): Error: System.ArgumentNullException: Value cannot be null. (Parameter 'source') at Microsoft.AspNetCore.Components.Web.Virtualization.Virtualize`1.BuildRenderTree(RenderTreeBuilder builder) at Microsoft.AspNetCore.Components.ComponentBase.<.ctor>b__6_0(RenderTreeBuilder builder) at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException) 4. Then set AllowVirtualization to "false", or remove @bind-Settings="@Settings" - the exception is gone. Filtering doesn't throw the exception.
Author
Owner

@Alex55040 commented on GitHub (Dec 6, 2022):

Or just copy my simplified example code for the Blazor component:

@using Radzen
@using System.Linq.Dynamic.Core
@page "/Test"

<RadzenDataGrid @bind-Settings="@Settings"
                AllowSorting="true"
                AllowFiltering="true"
                FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
                FilterMode="FilterMode.Advanced"
                AllowColumnResize="true"
                AllowColumnReorder="true"
                AllowColumnPicking="true"
                AllowPickAllColumns="true"
                AllowVirtualization="true"
                Data="@_employees"
                TItem="Employee"
                Count="@_count"
                LoadData="@LoadData"
                Style="height:400px">
    <Columns>
        <RadzenDataGridColumn TItem="Employee" Property="Id" Title="Id" />
        <RadzenDataGridColumn TItem="Employee" Property="Name" Title="Name" />
    </Columns>
</RadzenDataGrid>
@code {
    public class Employee
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }

    List<Employee> _source;

    IEnumerable<Employee> _employees;

    int _count;

    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();

        _source = new List<Employee>()
        {
            new Employee(){Id=0,Name="aaa"},
            new Employee(){Id=1,Name="bbb"},
            new Employee(){Id=2,Name="ccc"},
        };
    }

    protected void LoadData(LoadDataArgs args)
    {
        var query = _source.AsQueryable();

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

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

        _employees = query.Skip(args.Skip.Value).Take(args.Top.Value).ToList();
        _count = _employees.Count();
    }

    DataGridSettings _settings;
    public DataGridSettings Settings
    {
        get
        {
            return _settings;
        }
        set
        {
            if (_settings != value)
            {
                _settings = value;
            }
        }
    }
}
@Alex55040 commented on GitHub (Dec 6, 2022): Or just copy my simplified example code for the Blazor component: ``` @using Radzen @using System.Linq.Dynamic.Core @page "/Test" <RadzenDataGrid @bind-Settings="@Settings" AllowSorting="true" AllowFiltering="true" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive" FilterMode="FilterMode.Advanced" AllowColumnResize="true" AllowColumnReorder="true" AllowColumnPicking="true" AllowPickAllColumns="true" AllowVirtualization="true" Data="@_employees" TItem="Employee" Count="@_count" LoadData="@LoadData" Style="height:400px"> <Columns> <RadzenDataGridColumn TItem="Employee" Property="Id" Title="Id" /> <RadzenDataGridColumn TItem="Employee" Property="Name" Title="Name" /> </Columns> </RadzenDataGrid> ``` ``` @code { public class Employee { public int Id { get; set; } public string Name { get; set; } } List<Employee> _source; IEnumerable<Employee> _employees; int _count; protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); _source = new List<Employee>() { new Employee(){Id=0,Name="aaa"}, new Employee(){Id=1,Name="bbb"}, new Employee(){Id=2,Name="ccc"}, }; } protected void LoadData(LoadDataArgs args) { var query = _source.AsQueryable(); if (!string.IsNullOrEmpty(args.Filter)) { query = query.Where(args.Filter); } if (!string.IsNullOrEmpty(args.OrderBy)) { query = query.OrderBy(args.OrderBy); } _employees = query.Skip(args.Skip.Value).Take(args.Top.Value).ToList(); _count = _employees.Count(); } DataGridSettings _settings; public DataGridSettings Settings { get { return _settings; } set { if (_settings != value) { _settings = value; } } } } ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#663