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/> 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 and others added 7 commits December 5, 2025 09:45
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.
@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
Adds examples of virtual scrolling to the CDK and Material tables.
Sets up some tests for the virtual scrolling logic.
@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 3140223 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 3140223 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.

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

Labels

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