Skip to content

Conversation

@crisbeto
Copy link
Member

@crisbeto crisbeto commented Dec 5, 2025

Updates the CDK and Material tables to add support for virtual scrolling. This is based on the initial work in #21708 that I've productionized, made more ergonomic, fixed a few bugs, added tests and documentation.

To enable virtual scrolling for the table, you need to do two things.

  1. Add <cdk-virtual-scroll-viewport #viewport/> around it:
<cdk-virtual-scroll-viewport itemSize="52">
  <table mat-table>
    Same table as before...
  </table>
</cdk-virtual-scroll-viewport>
  1. Ensure that the viewport is scrollable in your CSS:
cdk-virtual-scroll-viewport {
  height: 600px;
  overflow: auto;
}

Related to #10122.

@crisbeto crisbeto added the target: minor This PR is targeted for the next minor release label Dec 5, 2025
@angular-robot angular-robot bot added detected: feature PR contains a feature commit area: docs Related to the documentation area: cdk/table area: cdk/scrolling labels Dec 5, 2025
@crisbeto crisbeto added the merge: preserve commits When the PR is merged, a rebase and merge should be performed label Dec 5, 2025
@crisbeto crisbeto force-pushed the table-virtual-scroll branch from e426476 to 3140223 Compare December 5, 2025 10:10
@crisbeto crisbeto marked this pull request as ready for review December 5, 2025 10:19
@pullapprove pullapprove bot requested review from ok7sai and tjshiu December 5, 2025 10:19
@crisbeto crisbeto requested a review from andrewseguin December 5, 2025 10:19
@@ -0,0 +1,37 @@
<p>Showing {{dataSource.length}} rows</p>

Copy link
Member Author

Choose a reason for hiding this comment

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

Note that there's a slight jump in this example when the column width changes. It's because the fixedLayout option is broken on the Material table. I'll send a separate PR since it may require some client fixes.

@andrewseguin andrewseguin added dev-app preview When applied, previews of the dev-app are deployed to Firebase docs: preview When applied, a preview of the documentation site is deployed to Firebase labels Dec 5, 2025
@github-actions
Copy link

github-actions bot commented Dec 5, 2025

Deployed dev-app for d4b368e to: https://ng-dev-previews-comp--pr-angular-components-32487-dev-ocum18z8.web.app

Note: As new commits are pushed to this pull request, this link is updated after the preview is rebuilt.

@github-actions
Copy link

github-actions bot commented Dec 5, 2025

Deployed docs-preview for d4b368e to: https://ng-dev-previews-comp--pr-angular-components-32487-docs-9to7g8zs.web.app

Note: As new commits are pushed to this pull request, this link is updated after the preview is rebuilt.

@crisbeto crisbeto force-pushed the table-virtual-scroll branch 7 times, most recently from 76465a4 to 27fe795 Compare December 8, 2025 12:04
@tjshiu tjshiu removed their request for review December 9, 2025 03:57
@crisbeto crisbeto force-pushed the table-virtual-scroll branch 4 times, most recently from 63ad51b to 6ddf015 Compare December 9, 2025 11:52
@crisbeto crisbeto force-pushed the table-virtual-scroll branch from 6ddf015 to 010c3d8 Compare December 9, 2025 11:56
@crisbeto crisbeto added the action: merge The PR is ready for merge by the caretaker label Dec 9, 2025
@crisbeto crisbeto removed the request for review from ok7sai December 9, 2025 12:14
crisbeto and others added 10 commits December 9, 2025 18:31
Revives the changes from angular#21708 and brings the up to date with the current repo.

Note that this is the initial step, we still need some fixes an cleanups.

Co-Authored-By: Michael-James Parsons <MichaelJamesParsons@users.noreply.github.com>
Fixes an issue where the table virtual scroller was jumping back to the top whenever it needs to re-render.
The table virtual scroller had a proxy class to work around a circular DI error. These changes rework the usage site so the workaround isn't required anymore.
We can put the factory in-line, instead of having to export it.
Combines the logic from the `CdkTableVirtualScroll` with the existing `CdkTable`. This allows us to remove the following steps from the virtual scrolling setup:
1. Having to import `CdkTableVirtualScroll`.
2. Having to set `fixedLayout` on the table.
3. Having to set `virtualScroll` on the table.
Exposes the `renderedContentOffset` stream on the virtual scroll viewport since it can be useful for users outside of the CDK table.
Implements the `measureRangeSize` method so the CDK table is compatible with auto-sizing.
Sets up some tests for the virtual scrolling logic.
Adds examples of virtual scrolling to the CDK and Material tables.
Adds an opt out that we can use internally to opt apps out of virtual scrolling. This allows us to keep the public API clean for the majority of users.
@crisbeto crisbeto force-pushed the table-virtual-scroll branch from 010c3d8 to d4b368e Compare December 9, 2025 17:31
@crisbeto crisbeto merged commit eccaecd into angular:main Dec 9, 2025
21 of 23 checks passed
@crisbeto
Copy link
Member Author

crisbeto commented Dec 9, 2025

This PR was merged into the repository. The changes were merged into the following branches:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: cdk/scrolling area: cdk/table area: docs Related to the documentation detected: feature PR contains a feature commit dev-app preview When applied, previews of the dev-app are deployed to Firebase docs: preview When applied, a preview of the documentation site is deployed to Firebase merge: preserve commits When the PR is merged, a rebase and merge should be performed target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants