Datagrid Reload Problem

Hello, i have a problem with the RadzenDatagrid. There are many similar requests here in the forum, but I haven't found a solution that works for me yet.

It's about manually updating the datagrid (e.g. after adding data through a user action). The datagrid has no filters, the data is provided via the LoadData event. I've reproduced this using a sample project (in the original, the data source is a REST API).

In the initial state, the datagrid is empty. I now create new elements in the data source using the Create button and want to update the display using Datagrid.Relaod(). So far, without success, even a StateHasChanged() doesn't produce any results.

So how do I get the datagrid to call the LoadData event? By the way, an initially existing data source is displayed correctly, but even then the problem is that changes are not recognized.

The code looks like this:

@page "/start"

<PageTitle>Start</PageTitle>

<RadzenRow
    Gap="5"
    RowGap="5">

    <RadzenColumn Size="12">
        <RadzenStack Orientation="Orientation.Horizontal" Gap="16px" JustifyContent="JustifyContent.Start">
            <RadzenButton
                Click="@(_ => OnCreateButtonClick())"
                Text="Create 20 Ids"
                ButtonStyle="ButtonStyle.Primary"/>
            <RadzenButton
                Click="@(_ => OnClearButtonClick())"
                Text="Delete All"
                ButtonStyle="ButtonStyle.Base"/>
        </RadzenStack>
    </RadzenColumn>

    <RadzenColumn>
        <RadzenDataGrid
            class="rz-border-start-0 rz-border-end-0"
            ref="@_dataGrid"
            Data="@(_filteredGuids)"
            Count="@_countAll"
            LoadData="@LoadData"
            AllowVirtualization="true"
            SelectionMode="DataGridSelectionMode.Single"
            @bind-Value="@_selectedIds"
            Style="width: 100%; height: 400px"
            Responsive="true">
            <Columns>
                <RadzenDataGridColumn Property="@nameof(GuidModel.Id)" Title="Id" Width="100px"/>
            </Columns>
        </RadzenDataGrid>
    </RadzenColumn>
</RadzenRow>

<EventConsole @ref="@_console" Style="width: 100%"/>

@code{
    private RadzenDataGrid<GuidModel>? _dataGrid;

    public IEnumerable<GuidModel>? _filteredGuids;
    
    private int _countAll;

    private IList<GuidModel>? _selectedIds;
    
    private EventConsole _console;

    private List<GuidModel>? _guidSource;
    
    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();
        //CreateGuids();
    }

    private Task LoadData(LoadDataArgs args)
    {
        if (_guidSource == null) {
            throw new InvalidOperationException("GuidSource is null.");
        }
        
        _filteredGuids = _guidSource.Skip(args.Skip ?? 0).Take(args.Top ?? _guidSource.Count);
        _countAll = _guidSource.Count;
        _console.Log($"LoadData: Count {_filteredGuids.Count()}, Skip {args.Skip}, Top {args.Top}");
        return Task.CompletedTask;
    }

    private Task OnCreateButtonClick()
    {
        CreateGuids();
        _dataGrid?.Reload();
        _console.Log($"{_guidSource?.Count} Guid-items in list.");
        return Task.CompletedTask;
    }

    private Task OnClearButtonClick()
    {
        _guidSource?.Clear();
        _dataGrid?.Reload();
        _console.Log($"{_guidSource?.Count} Guid-items in list.");
        return Task.CompletedTask;
    }

    private void CreateGuids()
    {
        _guidSource ??= [];
        
        for (var i = 0; i < 20; i++) {
            _guidSource.Add(new() { Id = Guid.NewGuid() });
        }
    }

By invoking Reload() method. Additionally you can attach the source code project instead the NuGet package to debug your case.

The Reload() method is used in the example above - in the ButtonClick handlers. But it does not result in LoadData() being called.

Cannot send the project as an attachment, the forum does not allow this for new users. Should I maybe send it by email?

Thank you for your attention...

You misunderstood my reply. You can attach Radzen.Blazor.csproj to your app to debug why the Reload() will not execute LoadData.

Hmh, as a user with a Pro subscription, I didn't really expect to have to worry about debugging the Radzen library myself. The example source code above illustrates the problem perfectly. Based on experience with other Blazor UI libraries, which work in a similar way, and the Radzen Components documentation, a ReLoad() should always trigger a LoadData(). If there are conditions for this, then they should be documented.

It would be great if you could take a look at the example and give me some feedback.

Our forum is free for everyone with no guaranteed support - for dedicated support you can use info@radzen.com. Make sure you include runnable code.

Okay, I'll send the description and a sample project via email. Thanks...

I've checked your project and I've noticed that your DataGrid instance reference is null:

This is due to the fact that the syntax where the reference is defined is wrong:

Should be:
@ref="@_dataGrid"
and in this case the reference will be set correctly:


and LoadData will be called:

Maybe next time you can quickly debug your code to save both of us time.

The missing @ before the ref was the whole problem. You're right, I should have debugged more without a filter in my head. But I was on a completely different path when troubleshooting, since everything worked with initial values.

Anyway: Thank you for your patience and support, have a great day...