DataGrid doesn't show updated data with LoadData, virtualization and custom filters #868

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

Originally created by @PWyrostek on GitHub (Jun 1, 2023).

Describe the bug
I have a DataGrid configured as follow:

<RadzenDataGrid @ref="grid" Data="@_projects" Count="@count" LoadData="@LoadData" TItem="{...}" AllowSorting="true" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive" AllowFiltering="true" AllowMultiColumnSorting="true" FilterMode="FilterMode.Advanced" GridLines="@DataGridGridLines.Both" RowSelect="@NavigateToCoordinations" ShowMultiColumnSortingIndex="true" Culture="@(new CultureInfo("pl-PL"))" AllowVirtualization="true" Style="height:72vh" VirtualizationOverscanCount="20">

I also have a text filter, that should filter by all the columns:

<RadzenTextBox @bind-Value=@searchText Style="width: 50ch;" Change=@SearchChange />

Currently, my SearchChange function looks like this:

private async Task SearchChange() { await grid.Reload(); //to trigger LoadData await InvokeAsync(StateHasChanged); }

And my LoadData like this: (for debugging purposes, to simplify - the searchText only filters by Name column)

void LoadData(LoadDataArgs args)
    {
        var query = _projectsDataSource.AsQueryable();
        var filtersApplied = false;

        if (!string.IsNullOrEmpty(searchText.Trim()))
        {
            query = query.Where($"(Name == null ? \"\" : Name).ToLower().Contains(\"{searchText}\".ToLower())");
            filtersApplied = true;
        }

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

        if (filtersApplied)
        {
            count = query.Count();
        }
        else
        {
            count = _projectsDataSource.Count();
        }

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

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

        InvokeAsync(StateHasChanged);
    }

While debugging, the _projects and count have correct values when applying my custom filter - but the grid doesn't show any records (it shows an empty grid, with a scroll that would indicate the amount of items before filtering).

When I apply any change to the grid (for example sorting on the name column) the data appears correctly.
When I turn the virtualization off, the data also loads correctly, immediately.

How can I ensure, that the grid shows the correct data, instead of an empty grid?

Originally created by @PWyrostek on GitHub (Jun 1, 2023). **Describe the bug** I have a DataGrid configured as follow: `<RadzenDataGrid @ref="grid" Data="@_projects" Count="@count" LoadData="@LoadData" TItem="{...}" AllowSorting="true" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive" AllowFiltering="true" AllowMultiColumnSorting="true" FilterMode="FilterMode.Advanced" GridLines="@DataGridGridLines.Both" RowSelect="@NavigateToCoordinations" ShowMultiColumnSortingIndex="true" Culture="@(new CultureInfo("pl-PL"))" AllowVirtualization="true" Style="height:72vh" VirtualizationOverscanCount="20">` I also have a text filter, that should filter by all the columns: `<RadzenTextBox @bind-Value=@searchText Style="width: 50ch;" Change=@SearchChange />` Currently, my SearchChange function looks like this: `private async Task SearchChange() { await grid.Reload(); //to trigger LoadData await InvokeAsync(StateHasChanged); }` And my LoadData like this: (for debugging purposes, to simplify - the searchText only filters by Name column) ``` void LoadData(LoadDataArgs args) { var query = _projectsDataSource.AsQueryable(); var filtersApplied = false; if (!string.IsNullOrEmpty(searchText.Trim())) { query = query.Where($"(Name == null ? \"\" : Name).ToLower().Contains(\"{searchText}\".ToLower())"); filtersApplied = true; } if (!string.IsNullOrEmpty(args.Filter)) { query = query.Where(args.Filter); filtersApplied = true; } if (filtersApplied) { count = query.Count(); } else { count = _projectsDataSource.Count(); } if (!string.IsNullOrEmpty(args.OrderBy)) { query = query.OrderBy(args.OrderBy); } _projects = query.Skip(args.Skip.Value).Take(args.Top.Value).ToList(); InvokeAsync(StateHasChanged); } ``` While debugging, the _projects and count have correct values when applying my custom filter - but the grid doesn't show any records (it shows an empty grid, with a scroll that would indicate the amount of items before filtering). When I apply any change to the grid (for example sorting on the name column) the data appears correctly. When I turn the virtualization off, the data also loads correctly, immediately. How can I ensure, that the grid shows the correct data, instead of an empty grid?
Author
Owner

@enchev commented on GitHub (Jun 1, 2023):

Hey @PWyrostek,

It will be better to use our forum to search or post your questions:
https://forum.radzen.com/t/refresh-datagrid-with-virtualization-after-filter-with-external-searchbox/14061/4

@enchev commented on GitHub (Jun 1, 2023): Hey @PWyrostek, It will be better to use our forum to search or post your questions: https://forum.radzen.com/t/refresh-datagrid-with-virtualization-after-filter-with-external-searchbox/14061/4
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#868