In RadzenDataGrid, the filtering works incorrectly in case Virtualization and LoadData is used. #1190

Closed
opened 2026-01-29 17:50:10 +00:00 by claunia · 8 comments
Owner

Originally created by @OndrejUzovic on GitHub (Apr 9, 2024).

If RadzenDataGrid has set Virtualization and LoadData then the filtering (Simple and Advanced) works incorrectly.

The filter does not return correct values in some cases.

Here are simple steps to reproduce the issue:

  1. open the example from Radzen Component Page: https://blazor.radzen.com/datagrid-virtualization-loaddata

  2. click on the first line in DataGrid and using the key 'PgDown' on the keyboard go 3 pages down. (So that the first line has OrderID=10255.

  3. Open the filter on the column OrderID.

  4. Enter the value 10300 and click 'Apply'.
    image

  5. The result is empty DataGrid with the message "No records to display." which is incorrect.
    image

The correct behavior would be if DataGrid lists two items.

Please, would it be possible to correct this behavior?

Originally created by @OndrejUzovic on GitHub (Apr 9, 2024). If RadzenDataGrid has set Virtualization and LoadData then the filtering (Simple and Advanced) works incorrectly. The filter does not return correct values in some cases. Here are simple steps to reproduce the issue: 1. open the example from Radzen Component Page: https://blazor.radzen.com/datagrid-virtualization-loaddata 2. click on the first line in DataGrid and using the key 'PgDown' on the keyboard go 3 pages down. (So that the first line has OrderID=10255. 3. Open the filter on the column OrderID. 4. Enter the value 10300 and click 'Apply'. ![image](https://github.com/radzenhq/radzen-blazor/assets/55758368/7d24a967-3cb6-4ea1-9e7d-47dfd21ca8b6) 5. The result is empty DataGrid with the message "No records to display." which is incorrect. ![image](https://github.com/radzenhq/radzen-blazor/assets/55758368/ed8c16cb-96fb-4d0e-a7ff-88a2a5fa5310) The correct behavior would be if DataGrid lists two items. Please, would it be possible to correct this behavior?
Author
Owner

@enchev commented on GitHub (Apr 10, 2024):

Here is what I see:
dg-virt-filter

@enchev commented on GitHub (Apr 10, 2024): Here is what I see: ![dg-virt-filter](https://github.com/radzenhq/radzen-blazor/assets/5804953/bd44a9d8-6778-4f10-a212-43aa02d7ac6c)
Author
Owner

@OndrejUzovic commented on GitHub (Apr 10, 2024):

Please, could you please try again? Sometimes it works.

Here are two captures showing the problem:

Here is my original scenario which on the first attempt works (as you did), but then as you can see the second attempt will not work:
Animation1

Here is other scenario, I moved the scrollbar somewhere and applied the filter which then returns empty list.
Animation2

@OndrejUzovic commented on GitHub (Apr 10, 2024): Please, could you please try again? Sometimes it works. Here are two captures showing the problem: Here is my original scenario which on the first attempt works (as you did), but then as you can see the second attempt will not work: ![Animation1](https://github.com/radzenhq/radzen-blazor/assets/55758368/d3ed6849-8042-4561-ae77-a488b218fc48) Here is other scenario, I moved the scrollbar somewhere and applied the filter which then returns empty list. ![Animation2](https://github.com/radzenhq/radzen-blazor/assets/55758368/c5cc7f89-9019-45e9-a04f-5e6562778c26)
Author
Owner

@enchev commented on GitHub (Apr 10, 2024):

I tried multiple times and every time it worked as it should.

@enchev commented on GitHub (Apr 10, 2024): I tried multiple times and every time it worked as it should.
Author
Owner

@OndrejUzovic commented on GitHub (Apr 10, 2024):

Hm, this is really strange it works for you.

I can reliably reproduce it on browsers Chrome and Edge. (I did not do any changes to your example code.)
Also users of my application complains about this problem.
Both videos I have attached clearly shows the incorrect behavior :-(

Can it be there is kind of a race condition problem? That could explain why you cannot reproduce it.

@OndrejUzovic commented on GitHub (Apr 10, 2024): Hm, this is really strange it works for you. I can reliably reproduce it on browsers Chrome and Edge. (I did not do any changes to your example code.) Also users of my application complains about this problem. Both videos I have attached clearly shows the incorrect behavior :-( Can it be there is kind of a race condition problem? That could explain why you cannot reproduce it.
Author
Owner

@OndrejUzovic commented on GitHub (Apr 10, 2024):

@enchev Could you please reopen this bug?
Maybe somebody could provide more info about that. And I plan to investigate it in more detail too.

@OndrejUzovic commented on GitHub (Apr 10, 2024): @enchev Could you please reopen this bug? Maybe somebody could provide more info about that. And I plan to investigate it in more detail too.
Author
Owner

@enchev commented on GitHub (Apr 11, 2024):

Hey @OndrejUzovic,

The issues are for reproducible problems. If you are looking for collaboration with other users you can use our forum.

@enchev commented on GitHub (Apr 11, 2024): Hey @OndrejUzovic, The issues are for reproducible problems. If you are looking for collaboration with other users you can use our forum.
Author
Owner

@OndrejUzovic commented on GitHub (Apr 25, 2024):

Hi @enchev I am regularly experiencing this issue, so I was trying to investigate it and also create an example to reproduce it easy.

I believe, following steps performed on the example bellow reliably reproduce the problem:

  1. Move the scrollbar to the very bottom position.
  2. Write the character 0 into the filter.

Here is the video:
Animation2

Here is the simple code:

@page "/"

@using Radzen;
@using Radzen.Blazor;
@using System.Linq.Dynamic.Core

<RadzenDataGrid TItem="Dummy" LoadData="@OnLoadData" Data="@myLoadedData" Count="@myCount" AllowVirtualization=true
                AllowFiltering=true FilterMode="FilterMode.Simple"
                Style="width:400px; height:400px">
    <Columns>
        <RadzenDataGridColumn TItem="Dummy" Property="Id" Title="Id">
            <FooterTemplate>
                @myCount
            </FooterTemplate>
        </RadzenDataGridColumn>
    </Columns>
</RadzenDataGrid>


@code {
    private class Dummy
    {
        public string Id { get; set; }
    }

    private List<Dummy> myEmployees = new List<Dummy>();

    private IEnumerable<Dummy> myLoadedData;
    private int myCount;


    protected override void OnInitialized()
    {
        for (int i = 0; i < 100; ++i)
        {
            myEmployees.Add(new Dummy() { Id = $"ID_{i.ToString()}" });
        }
    }

    private async Task OnLoadData(LoadDataArgs args)
    {
        await Task.Yield();

        var query = myEmployees.AsQueryable();

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

        myCount = await Task.FromResult(query.Count());

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

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

I believe the problem is that when the method OnLoadData is called the first time after the filter was set, it has args.Skip set to 80.
Therefore when Skip and Take are applied into the query it returns 0 items.

Should not be Skip set to 0 when OnLoad is called the first time after setting the filter?
Or do I miss something here?

@OndrejUzovic commented on GitHub (Apr 25, 2024): Hi @enchev I am regularly experiencing this issue, so I was trying to investigate it and also create an example to reproduce it easy. I believe, following steps performed on the example bellow reliably reproduce the problem: 1. Move the scrollbar to the very bottom position. 2. Write the character 0 into the filter. Here is the video: ![Animation2](https://github.com/radzenhq/radzen-blazor/assets/55758368/1ce497a4-fed5-457d-8f4d-3c95e45fe1cd) Here is the simple code: ``` @page "/" @using Radzen; @using Radzen.Blazor; @using System.Linq.Dynamic.Core <RadzenDataGrid TItem="Dummy" LoadData="@OnLoadData" Data="@myLoadedData" Count="@myCount" AllowVirtualization=true AllowFiltering=true FilterMode="FilterMode.Simple" Style="width:400px; height:400px"> <Columns> <RadzenDataGridColumn TItem="Dummy" Property="Id" Title="Id"> <FooterTemplate> @myCount </FooterTemplate> </RadzenDataGridColumn> </Columns> </RadzenDataGrid> @code { private class Dummy { public string Id { get; set; } } private List<Dummy> myEmployees = new List<Dummy>(); private IEnumerable<Dummy> myLoadedData; private int myCount; protected override void OnInitialized() { for (int i = 0; i < 100; ++i) { myEmployees.Add(new Dummy() { Id = $"ID_{i.ToString()}" }); } } private async Task OnLoadData(LoadDataArgs args) { await Task.Yield(); var query = myEmployees.AsQueryable(); if (!string.IsNullOrEmpty(args.Filter)) { query = query.Where(args.Filter); } myCount = await Task.FromResult(query.Count()); if (!string.IsNullOrEmpty(args.OrderBy)) { query = query.OrderBy(args.OrderBy); } myLoadedData = await Task.FromResult(query.Skip(args.Skip.Value).Take(args.Top.Value).ToList()); } } ``` I believe the problem is that when the method `OnLoadData` is called the first time after the filter was set, it has `args.Skip` set to 80. Therefore when `Skip` and `Take` are applied into the query it returns 0 items. Should not be Skip set to 0 when `OnLoad` is called the first time after setting the filter? Or do I miss something here?
Author
Owner

@enchev commented on GitHub (Apr 26, 2024):

Again, check our demos
image

@enchev commented on GitHub (Apr 26, 2024): Again, check our demos ![image](https://github.com/radzenhq/radzen-blazor/assets/5804953/222576f7-4ec5-4c09-a2ad-298b5f96981a)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#1190