RadzenDataGrid: OnPageSizeChanged and ReloadOnFirstRender redundantly reload #881

Closed
opened 2026-01-29 17:45:45 +00:00 by claunia · 4 comments
Owner

Originally created by @evandixon on GitHub (Jun 13, 2023).

Describe the bug
On the first render of a data grid with both a LoadData delegate and a manually specified PageSize, the LoadData delegate is called twice, once by PagedDataBoundComponent<>.OnPageSizeChanged and once by PagedDataBoundComponent<>.ReloadOnFirstRender.

To Reproduce
Steps to reproduce the behavior:

  1. Create a RadzenDataGrid
  2. Define both the LoadData and the PageSize parameters in any order
  3. Observe the LoadData implementation being called twice on the first page load.

Expected behavior
The initial set of PageSize doesn't trigger a reload when ReloadOnFirstRender is going to trigger a reload

Originally created by @evandixon on GitHub (Jun 13, 2023). **Describe the bug** On the first render of a data grid with both a LoadData delegate and a manually specified PageSize, the LoadData delegate is called twice, once by `PagedDataBoundComponent<>.OnPageSizeChanged` and once by `PagedDataBoundComponent<>.ReloadOnFirstRender`. **To Reproduce** Steps to reproduce the behavior: 1. Create a RadzenDataGrid 2. Define both the LoadData and the PageSize parameters in any order 3. Observe the LoadData implementation being called twice on the first page load. **Expected behavior** The initial set of PageSize doesn't trigger a reload when ReloadOnFirstRender is going to trigger a reload
Author
Owner

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

Both PageSize and LoadData are used in this demo however LoadData will be called only once:
https://blazor.radzen.com/datagrid-loaddata

@enchev commented on GitHub (Jun 14, 2023): Both PageSize and LoadData are used in this demo however LoadData will be called only once: https://blazor.radzen.com/datagrid-loaddata
Author
Owner

@evandixon commented on GitHub (Jun 14, 2023):

On that demo, I added Console.WriteLine("Reload called. Stack trace: " + Environment.StackTrace.Replace("\n", "\\n")); to line 102 at the very top of LoadData, and looking in the console shows that LoadData is indeed being called twice, once from ReloadOnFirstRender and once from PageSizeChanged. It's easier to see when LoadData makes a network call since you can see two distinct network requests.

@evandixon commented on GitHub (Jun 14, 2023): On that demo, I added `Console.WriteLine("Reload called. Stack trace: " + Environment.StackTrace.Replace("\n", "\\n"));` to line 102 at the very top of LoadData, and looking in the console shows that LoadData is indeed being called twice, once from ReloadOnFirstRender and once from PageSizeChanged. It's easier to see when LoadData makes a network call since you can see two distinct network requests.
Author
Owner

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

Hey @evandixon,

I've used the debugger to check the same:
loaddata-pagesize

@enchev commented on GitHub (Jun 15, 2023): Hey @evandixon, I've used the debugger to check the same: ![loaddata-pagesize](https://github.com/radzenhq/radzen-blazor/assets/5804953/f2087b91-38b3-4ad6-b71c-84a7d83f611a)
Author
Owner

@evandixon commented on GitHub (Jun 15, 2023):

@enchev Turns out there's a race condition with the reload caused by OnPageSizeChanged not being awaited by the setter of PageSize. If the reload works quickly there, ReloadOnFirstRender will see that there's data and not reload. Adding a await Task.Delay(1000); to the start of LoadData results in ReloadOnFirstRender loading before OnPageSizeChanged completes.

@evandixon commented on GitHub (Jun 15, 2023): @enchev Turns out there's a race condition with the reload caused by OnPageSizeChanged not being awaited by the setter of PageSize. If the reload works quickly there, ReloadOnFirstRender will see that there's data and not reload. Adding a `await Task.Delay(1000);` to the start of LoadData results in ReloadOnFirstRender loading before OnPageSizeChanged completes.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#881