-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
MudTable: Scroll to row & focus cell #11569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MudTable: Scroll to row & focus cell #11569
Conversation
…com/Anu6is/MudBlazor into 5445-MudTable-ScrollToRow_FocusCell
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #11569 +/- ##
=======================================
Coverage 91.31% 91.32%
=======================================
Files 466 466
Lines 14725 14728 +3
Branches 2870 2871 +1
=======================================
+ Hits 13446 13450 +4
- Misses 636 637 +1
+ Partials 643 641 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…l' into 5445-MudTable-ScrollToRow_FocusCell
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds two new public APIs, ScrollToItemAsync and FocusCellAsync, to allow programmatic scrolling and cell focusing in MudTable. Key changes include:
- New JavaScript helpers in
mudTableCell.jsand expandedmudScrollManager.jsfor scrolling and cell focus/select. - Extended C# scroll services (
IScrollManager&ScrollManager) and injected them intoMudTable, plus new methods inMudTable.razor.cs. - Added
RowIdsupport inMudTr, wired up row IDs inMudTable.razor, updated unit tests, mocks, and documentation with an example.
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/MudBlazor/TScripts/mudTableCell.js | New JS class for focusing and selecting table cells |
| src/MudBlazor/TScripts/mudScrollManager.js | Added scrollToVirtualizedItem helper |
| src/MudBlazor/Services/Scroll/IScrollManager.cs | Declared ScrollToVirtualizedItemAsync |
| src/MudBlazor/Services/Scroll/ScrollManager.cs | Implemented ScrollToVirtualizedItemAsync |
| src/MudBlazor/Components/Table/MudTr.razor.cs and MudTr.razor | Added RowId parameter and applied id attribute |
| src/MudBlazor/Components/Table/MudTable.razor.cs and .razor | Introduced ScrollToItemAsync & FocusCellAsync, row-ID generation |
| src/MudBlazor.UnitTests/Components/TableTests.cs | New tests for scrolling and focus behavior |
| src/MudBlazor.UnitTests.Shared/Mocks/MockScrollServices.cs | Extended mock with ScrollToVirtualizedItemAsync |
| src/MudBlazor.Docs/Pages/Components/Table/TablePage.razor | Added docs section for programmatic scroll & focus |
| src/MudBlazor.Docs/.../Examples/TableScrollFocusExample.razor | Added example demonstrating new APIs |
Comments suppressed due to low confidence (3)
src/MudBlazor/Components/Table/MudTable.razor.cs:98
- [nitpick] Calling
FilteredItems.ToList()for each row can be expensive on large tables. Consider materializingFilteredItems.ToList()once outside the loop and reusing it to avoid repeated allocations.
return true;
src/MudBlazor.UnitTests/Components/TableTests.cs:2746
- The
FocusCellAsyncimplementation also callsmudTableCell.selectCell, but the test only verifiesfocusCell. Add a verification for theselectCellinvocation to fully cover the behavior.
jsRuntimeMock.Verify(x => x.InvokeAsync<IJSVoidResult>("mudTableCell.focusCell", It.IsAny<object[]>()), Times.Once);
src/MudBlazor/Components/Table/MudTable.razor.cs:821
- The selector uses an extra "$" inside the interpolated string, resulting in an invalid CSS selector like
tbody > tr:nth-child($6). Change it tovar selector = $"tbody > tr:nth-child({itemIndex + 1})";.
var selector = $"tbody > tr:nth-child(${itemIndex + 1})";
versile2
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, I made a comment or two but they are semantics. The Docs I would definitely change to match our other patterns. I was a little curious on the calling focus and select both and separately but I'm sure you had your reasons.
|
ScarletKuro
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, just requires few indents fixes
| var comp = Context.RenderComponent<MudTable<TestItem>>(parameters => parameters | ||
| .Add(p => p.Items, items) | ||
| .Add(p => p.Virtualize, false) | ||
| .Add(p => p.HeaderContent, builder => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indent
| .Add(p => p.Virtualize, true) | ||
| .Add(p => p.Height, "300px") | ||
| .Add(p => p.FixedHeader, true) | ||
| .Add(p => p.HeaderContent, builder => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indent
| <div class="mud-table-container @TableContainerClass" style="@TableContainerStyle @(GetHorizontalScrollbarStyle())"> | ||
| <table class="@TableClassname"> | ||
| <div id="@_tableId" class="mud-table-container @TableContainerClass" style="@TableContainerStyle @(GetHorizontalScrollbarStyle())"> | ||
| <table class="@TableClassname"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indent
|
Any chance on this moving forward? I need this exact feature. |



Description
Adds two new public APIs to
MudTableScrollToItemAsync: Scrolls to a specific item within the table into viewFocusCellAsync: Focuses a specific cell by first scrolling to bring the item into view, performing a click and then a selectResolves #5445
How Has This Been Tested?
Visually and unit test
Type of Changes
table.demo.mp4
Checklist
dev).