Skip to content

[DataGrid] Re-render the grid after RefreshDataAsync with Virtualize - #5488

Merged
Denis Voituron (dvoituron) merged 2 commits into
microsoft:devfrom
giga487:fix/datagrid-virtualize-refresh
Oct 21, 2026
Merged

Denis Voituron (dvoituron) merged 2 commits into
microsoft:devfrom
giga487:fix/datagrid-virtualize-refresh

Conversation

@giga487

@giga487 Pierluigi Amato (giga487) commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Pull Request

📖 Description

When Virtualize="true", calling RefreshDataAsync() refreshes the data but does not re-render the grid itself when the total item count does not change.

Since #4972, the Virtualize branch of RefreshDataCoreAsync returns early after delegating to Virtualize.RefreshDataAsync() (to avoid a second query). That early return also skips the final StateHasChanged(), which was the only place the grid re-rendered. ProvideVirtualizedItemsAsync only renders the grid on the first result or when the total count changes, so a plain refresh left the grid stale.

The comment on RefreshDataCoreAsync already says it is "Same as RefreshDataAsync, except without forcing a re-render". So the public method now forces the render, as ASP.NET Core QuickGrid does. It uses await InvokeAsync(StateHasChanged) rather than a direct StateHasChanged(), so RefreshDataAsync (and the public APIs built on it: SetSortAsync, SortByColumnAsync, ...) can still be called from outside the renderer's synchronization context. A direct call breaks 60 existing tests that do this.

In the non-virtualized path an InvokeAsync(StateHasChanged) is already queued; the extra render request is batched by Blazor.

🎫 Issues

👩‍💻 Reviewer Notes

The fix is a single line in FluentDataGrid.RefreshDataAsync. Please take a look at the choice of InvokeAsync(StateHasChanged) over StateHasChanged() (see above).

📑 Test Plan

  • Added FluentDataGrid_Virtualize_RefreshDataAsync_RerendersGrid: a virtualized grid with a stable item count must re-render after RefreshDataAsync(). It fails without the fix and passes with it.
  • Ran the full unit test suite on net10.0: 4902/4904 passed. The 2 failures are in CalendarExtendedTests.GetDaysOfWeek_ReturnsCorrectDays (date parsing in the DateTimes utilities, not touched by this PR).
  • Not done: manual smoke test in the demo app.

✅ 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.

AI contribution declaration

AI assistance is allowed; fully AI-generated or autonomous pull requests without meaningful human review are not accepted. See the AI contribution policy.

  • I have read and followed the AI contribution policy.
  • I have personally reviewed and understood all changes, tested them, and take responsibility for this contribution.

Component-specific

  • I have modified an existing component
  • I have validated the Unit Tests for an existing component

⏭ Next Steps

None.

Since microsoft#4972 the Virtualize branch of RefreshDataCoreAsync returns early
after delegating to Virtualize.RefreshDataAsync, skipping the final
StateHasChanged. When the total item count did not change, the grid
itself was never re-rendered.

RefreshDataAsync now renders the grid after refreshing, as QuickGrid
does. InvokeAsync keeps it callable from outside the renderer's
synchronization context.

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.

🟢 Approval recommended

The focused fix restores rendering without changing query behavior and includes targeted regression coverage.

No open issues 🎉

What changed in this PR

Fixes the virtualized DataGrid refresh regression introduced by #4972 when the total item count stays unchanged.

Changes:

  • Requests a grid render after refreshing data using renderer-safe dispatch.
  • Adds regression coverage for refreshes with a stable item count.
File Description
tests/​Core/​Components/​DataGrid/​FluentDataGridTests.razor Tests that virtualized refreshes re-render the grid.
src/​Core/​Components/​DataGrid/​FluentDataGrid.razor.cs Adds InvokeAsync(StateHasChanged) after refreshing data.

Review effort: Balanced

@giga487

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

@dvoituron
Denis Voituron (dvoituron) merged commit a25ed58 into microsoft:dev Oct 21, 2026
4 checks passed
This was referenced Nov 16, 2026
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.

3 participants