DataGrid changes to page 1 when its bound data changes #565

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

Originally created by @elylv on GitHub (Oct 3, 2022).

Related: #591 #598

Reporting that the bug referenced in #591 seems to be present on v4.1.6
I have a datagrid bound to Data only (with no LoadData).
The Data I'm binding to is dynamic, in that it is a get => to another list, basically just filtering things out .Where(x => x.Active)
When I select an item on page 2 of the grid, the grid changes to page 1.
I presume that when I select an item, a StateHasChanged() is fired and the Data is recalculated, and I'm experiencing the same bug as #591. I guess the fix from #598 reintroduced this bug.

Originally created by @elylv on GitHub (Oct 3, 2022). Related: #591 #598 Reporting that the bug referenced in #591 seems to be present on v4.1.6 I have a datagrid bound to Data only (with no LoadData). The Data I'm binding to is dynamic, in that it is a get => to another list, basically just filtering things out .Where(x => x.Active) When I select an item on page 2 of the grid, the grid changes to page 1. I presume that when I select an item, a StateHasChanged() is fired and the Data is recalculated, and I'm experiencing the same bug as #591. I guess the fix from #598 reintroduced this bug.
Author
Owner

@enchev commented on GitHub (Oct 4, 2022):

I'm afraid that there is nothing we can do in this case - we should reset page on Data change and Blazor will always re-evaluate expressions on StateHasChanged(). To avoid this you should not use expressions for Data. For example:
image

@enchev commented on GitHub (Oct 4, 2022): I'm afraid that there is nothing we can do in this case - we should reset page on Data change and Blazor will always re-evaluate expressions on StateHasChanged(). To avoid this you should not use expressions for Data. For example: ![image](https://user-images.githubusercontent.com/5804953/193756402-24e364b8-fb6e-4e76-8094-d1b222a606f4.png)
Author
Owner

@elylv commented on GitHub (Oct 4, 2022):

@enchev I am certain this is a bug, because it has only recently started happening. I think this should be reopened. It should just keep a note of which page in the data it is on, and not reset that when the data is updated. This limits the usefulness of the grid, for example:
I am displaying a list of items in the grid, with the ability to 'delete' items.
Deletion of the items does not remove them from the list, it simply adds a flag on the item called IsDeleted.
Data is bound to items.Where(x => !x.IsDeleted)
Previously (probably a couple of versions ago), I could 'delete' an item on the grid by simply setting IsDeleted, and it would disappear from the grid.
This still works, however, now every time ValueChanged fired (on selection of an item), the pager switches to page 1. It used to remain on the current page on every ValueChanged in the past.

Your workaround will not work for me, I would need to maintain two separate lists of items. The master list of all objects, and a second list of non-deleted items just for the grid to display. This would require syncing between the lists on every change to one of the list items.

@elylv commented on GitHub (Oct 4, 2022): @enchev I am certain this is a bug, because it has only recently started happening. I think this should be reopened. It should just keep a note of which page in the data it is on, and not reset that when the data is updated. This limits the usefulness of the grid, for example: I am displaying a list of items in the grid, with the ability to 'delete' items. Deletion of the items does not remove them from the list, it simply adds a flag on the item called IsDeleted. Data is bound to items.Where(x => !x.IsDeleted) Previously (probably a couple of versions ago), I could 'delete' an item on the grid by simply setting IsDeleted, and it would disappear from the grid. This still works, however, now every time ValueChanged fired (on selection of an item), the pager switches to page 1. It used to remain on the current page on every ValueChanged in the past. Your workaround will not work for me, I would need to maintain two separate lists of items. The master list of all objects, and a second list of non-deleted items just for the grid to display. This would require syncing between the lists on every change to one of the list items.
Author
Owner

@elylv commented on GitHub (Oct 4, 2022):

This seems to be the offending line:
3c9368b05f/Radzen.Blazor/RadzenDataGrid.razor.cs (L1491)

It seems that whole if{} section was missing in previous commits. Can we just remove the setting of the skip value and current page?

@elylv commented on GitHub (Oct 4, 2022): This seems to be the offending line: https://github.com/radzenhq/radzen-blazor/blob/3c9368b05fd700ea63ca41ab5a9d9f28958c13b1/Radzen.Blazor/RadzenDataGrid.razor.cs#L1491 It seems that whole if{} section was missing in previous commits. Can we just remove the setting of the skip value and current page?
Author
Owner

@elylv commented on GitHub (Oct 4, 2022):

As a workaround, I have set Page=@OnPage on the datagrid, with the OnPage function just being empty. This causes Page.HasDelegate and the if() evaluation on that section of code to be false. This seems to restore the previous functionality.

@elylv commented on GitHub (Oct 4, 2022): As a workaround, I have set Page=@OnPage on the datagrid, with the OnPage function just being empty. This causes Page.HasDelegate and the if() evaluation on that section of code to be false. This seems to restore the previous functionality.
Author
Owner

@hal9000lives commented on GitHub (Apr 7, 2024):

The above fix by elylv partially works. It does stop the page number resetting to 1, however, if the browser page is scrolled, it will reset the browser to the top of the page.

@hal9000lives commented on GitHub (Apr 7, 2024): The above fix by elylv partially works. It does stop the page number resetting to 1, however, if the browser page is scrolled, it will reset the browser to the top of the page.
Author
Owner

@Stuart88 commented on GitHub (Jul 29, 2024):

Clearly still a bug as this issue has been affecting me and adding Page="@(() => {})" resolved it.

@Stuart88 commented on GitHub (Jul 29, 2024): Clearly still a bug as this issue has been affecting me and adding ` Page="@(() => {})"` resolved it.
Author
Owner

@philliprfoster commented on GitHub (Dec 5, 2024):

Clearly still a bug as this issue has been affecting me and adding Page="@(() => {})" resolved it.

Thanks, Stuart88! I was having the exact same problem with a subgrid and adding this fixed the problem.

@philliprfoster commented on GitHub (Dec 5, 2024): > Clearly still a bug as this issue has been affecting me and adding ` Page="@(() => {})"` resolved it. Thanks, Stuart88! I was having the exact same problem with a subgrid and adding this fixed the problem.
Author
Owner

@t-schreibs commented on GitHub (Aug 14, 2025):

Clearly still a bug as this issue has been affecting me and adding Page="@(() => {})" resolved it.

I was stuck on the same issue - this resolved it for me too!

@t-schreibs commented on GitHub (Aug 14, 2025): > Clearly still a bug as this issue has been affecting me and adding ` Page="@(() => {})"` resolved it. I was stuck on the same issue - this resolved it for me too!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#565