Skip to content

[dev-v5][DataGrid] Improve Virtualize handling and data loading#4972

Open
miguelhasse wants to merge 6 commits into
microsoft:dev-v5from
miguelhasse:improve-datagrid-virtualize-handling
Open

[dev-v5][DataGrid] Improve Virtualize handling and data loading#4972
miguelhasse wants to merge 6 commits into
microsoft:dev-v5from
miguelhasse:improve-datagrid-virtualize-handling

Conversation

@miguelhasse

@miguelhasse miguelhasse commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

📖 Description

Refined the virtualized data loading logic in FluentDataGrid.razor and its code-behind to ensure that data is only loaded when the Virtualize component is ready, and to prevent unnecessary or duplicate data loads during the initial render.

Improved async data loading by properly handling cancellation tokens, including catching cancellation exceptions and returning default values when operations are cancelled. This prevents unnecessary errors and ensures the UI remains responsive.

👩‍💻 Reviewer Notes

The following examples can be used to test behavior enhancements:

AdventureWorks to test using EntityFrameworkAdapter with SQL Server
TripPin to test using ODataAdapter

✅ Checklist

General

  • I have added tests for my changes.
  • I have tested my changes.
  • I have updated the project documentation to reflect my changes.
  • I have read the CONTRIBUTING documentation and followed the standards for this project.

Component-specific

  • I have added a new component
  • I have added Unit Tests for my new component
  • I have modified an existing component
  • I have validated the Unit Tests for an existing component

- Only render empty content if total count is zero and Virtualize is initialized
- In RefreshDataCoreAsync, check Virtualize flag and avoid redundant data loading if component is not ready
- Make Task.Delay in ProvideVirtualizedItemsAsync cancellable
- In ResolveItemsRequestA, skip ToArrayAsync if count is zero and add cancellation checks before and after data retrieval for better efficiency and responsiveness
Copilot AI review requested due to automatic review settings June 26, 2026 15:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refines FluentDataGrid’s virtualization data-loading flow so the grid waits for the Virtualize child component to be available before issuing its first load, and improves cancellation handling during virtualized and async-query execution.

Changes:

  • Defer initial virtualized refresh until the Virtualize component reference is available to avoid duplicate/early loads.
  • Improve cancellation behavior in the virtualized debounce delay and async query execution (count + page fetch).
  • Adjust empty-state rendering for virtualized grids to avoid showing empty content before Virtualize is ready.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/Core/Components/DataGrid/FluentDataGrid.razor.cs Updates refresh/virtualized provider logic and async query execution cancellation handling.
src/Core/Components/DataGrid/FluentDataGrid.razor Tweaks empty-state rendering condition for virtualized mode to avoid premature empty UI.

Comment thread src/Core/Components/DataGrid/FluentDataGrid.razor.cs
Comment thread src/Core/Components/DataGrid/FluentDataGrid.razor.cs
@miguelhasse miguelhasse changed the title [DataGrid] Improve Virtualize handling and data loading [dev-v5][DataGrid] Improve Virtualize handling and data loading Jun 26, 2026
miguelhasse and others added 2 commits June 26, 2026 16:53
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Updated the condition for fetching items to ensure request.Count is not null and greater than zero. This prevents potential null reference issues and makes the code more robust when handling nullable request counts.

@vnbaaij vnbaaij left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still need to review

Allow resultArray fetching when request.Count is null or > 0, instead of only when it is > 0. This ensures items are fetched even if request.Count is not specified.
Changed the test assertion to require at least one row instead of exactly two, making the test less strict and more robust to variations in rendered row count.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants