Skip to content

Expose InitialItemIndex parameter and ScrollToItemAsync method on QuickGrid  - #67914

Merged
ilonatommy merged 7 commits into
mainfrom
quickgrid-scroll-initialindex-apis
Jul 21, 2026
Merged

Expose InitialItemIndex parameter and ScrollToItemAsync method on QuickGrid #67914
ilonatommy merged 7 commits into
mainfrom
quickgrid-scroll-initialindex-apis

Conversation

@ilonatommy

@ilonatommy ilonatommy commented Jul 20, 2026

Copy link
Copy Markdown
Member

Summary

Adds two public, non-experimental APIs to QuickGrid<TGridItem> that forward to its inner Virtualize component:

  • InitialItemIndex parameter - scrolls to the given row on first interactive render (clamped, applied once).
  • ScrollToItemAsync(int itemIndex, CancellationToken) method - programmatically scrolls to a row, aligning it to the top. Last call wins; throws InvalidOperationException when Virtualize is disabled or the grid isn't rendered yet.

These mirror the existing Virtualize.InitialItemIndex / Virtualize.ScrollToItemAsync APIs from #66328.

API surface

namespace Microsoft.AspNetCore.Components.QuickGrid;

public partial class QuickGrid<TGridItem> : ComponentBase
{
    // Applies only when Virtualize is true.
    [Parameter]
    public int InitialItemIndex { get; set; }

    public Task ScrollToItemAsync(int itemIndex, CancellationToken cancellationToken = default);
}

Usage example

<QuickGrid @ref="_grid" Items="@people" Virtualize="true" ItemSize="50" InitialItemIndex="500">
    <PropertyColumn Property="@(p => p.Name)" />
    <PropertyColumn Property="@(p => p.Age)" />
</QuickGrid>

<button @onclick="() => _grid.ScrollToItemAsync(500)">Jump to 500</button>

@code {
    QuickGrid<Person> _grid = default!;
}

@ilonatommy ilonatommy added this to the 11.0-preview7 milestone Jul 20, 2026
@ilonatommy ilonatommy self-assigned this Jul 20, 2026
@ilonatommy
ilonatommy requested a review from a team as a code owner July 20, 2026 16:53
Copilot AI review requested due to automatic review settings July 20, 2026 16:53
@ilonatommy ilonatommy added area-blazor Includes: Blazor, Razor Components feature-blazor-quickgrid labels Jul 20, 2026

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 exposes InitialItemIndex and ScrollToItemAsync as public, non-experimental APIs on QuickGrid<TGridItem> by forwarding to the underlying Virtualize component, and adds new BasicTestApp + E2E coverage to validate the behavior end-to-end.

Changes:

  • Added QuickGrid<TGridItem>.InitialItemIndex parameter and QuickGrid<TGridItem>.ScrollToItemAsync(...) method, forwarding to Virtualize.
  • Forwarded InitialItemIndex from QuickGrid to the inner <Virtualize> instance.
  • Added a new BasicTestApp component and new E2E tests covering scrolling/initial-index behaviors (including variable height, provider delay, rapid calls, and cancellation).

Reviewed changes

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

Show a summary per file
File Description
src/Components/test/testassets/BasicTestApp/QuickGridTest/QuickGridScrollComponent.razor New test asset component exercising QuickGrid’s scroll APIs in a scrollable container.
src/Components/test/testassets/BasicTestApp/Index.razor Adds the new QuickGrid scroll test component to the test asset menu.
src/Components/test/E2ETest/Tests/VirtualizationTest.cs Adds E2E coverage for QuickGrid scroll-to-item and initial-index scenarios.
src/Components/QuickGrid/Microsoft.AspNetCore.Components.QuickGrid/src/QuickGrid.razor.cs Adds the new public parameter and method (and validation) to QuickGrid.
src/Components/QuickGrid/Microsoft.AspNetCore.Components.QuickGrid/src/QuickGrid.razor Forwards InitialItemIndex into the inner Virtualize component.
src/Components/QuickGrid/Microsoft.AspNetCore.Components.QuickGrid/src/PublicAPI.Unshipped.txt Declares the newly added public API surface for API review tooling.

Comment thread src/Components/test/E2ETest/Tests/VirtualizationTest.cs Outdated
ilonatommy and others added 5 commits July 20, 2026 19:54
ScrollToItem/InitialItemIndex on QuickGrid (a table) uses the manual
compensation path. When an async ItemsProvider renders placeholders first,
C# invokes alignToItemAt right after committing the render, while the
MutationObserver that applies the spacer reserved-height styles is still
pending. measureLocalChildOffset then reads stale (near-zero) spacer heights,
so the target row measures near the top and the scroll delta is far too small
(landed ~196px with a 10844px spacer, undershooting the target by ~3 rows).

Flush the pending style mutations before measuring so the spacer heights, and
therefore the target row offset, reflect the committed window.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: d5314ec1-7255-4744-bb91-0225d535097f

@dariatiurina dariatiurina 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.

Looks great!

Comment thread src/Components/test/E2ETest/Tests/VirtualizationTest.cs Outdated
Comment thread src/Components/test/E2ETest/Tests/VirtualizationTest.cs Outdated
Comment thread src/Components/test/E2ETest/Tests/VirtualizationTest.cs Outdated
@ilonatommy
ilonatommy enabled auto-merge (squash) July 21, 2026 09:02
@ilonatommy
ilonatommy merged commit eb281b1 into main Jul 21, 2026
26 checks passed
@ilonatommy
ilonatommy deleted the quickgrid-scroll-initialindex-apis branch July 21, 2026 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-blazor Includes: Blazor, Razor Components feature-blazor-quickgrid

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants