Skip to content

Commit 1687208

Browse files
committed
refactor(cdk/table): add internal opt out for virtual scrolling
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.
1 parent 361a053 commit 1687208

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

src/cdk/table/table.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,14 @@ export class CdkTable<T>
467467
/** Emits when the footer rows sticky state changes. */
468468
private readonly _footerRowStickyUpdates = new Subject<StickyUpdate>();
469469

470+
/**
471+
* Whether to explicitly disable virtual scrolling even if there is a virtual scroll viewport
472+
* parent. This can't be changed externally, whereas internally it is turned into an input that
473+
* we use to opt out existing apps that were implementing virtual scroll before we added support
474+
* for it.
475+
*/
476+
private readonly _disableVirtualScrolling = false;
477+
470478
/** Aria role to apply to the table's cells based on the table's own role. */
471479
_getCellRole(): string | null {
472480
// Perform this lazily in case the table's role was updated by a directive after construction.
@@ -565,7 +573,7 @@ export class CdkTable<T>
565573
get fixedLayout(): boolean {
566574
// Require a fixed layout when virtual scrolling is enabled, otherwise
567575
// the element the header can jump around as the user is scrolling.
568-
return this._virtualScrollViewport ? true : this._fixedLayout;
576+
return this._virtualScrollEnabled() ? true : this._fixedLayout;
569577
}
570578
set fixedLayout(value: boolean) {
571579
this._fixedLayout = value;
@@ -640,7 +648,7 @@ export class CdkTable<T>
640648
this._isNativeHtmlTable = this._elementRef.nativeElement.nodeName === 'TABLE';
641649
this.viewChange = new BehaviorSubject<ListRange>({
642650
start: 0,
643-
end: this._virtualScrollViewport ? 0 : Number.MAX_VALUE,
651+
end: this._virtualScrollEnabled() ? 0 : Number.MAX_VALUE,
644652
});
645653

646654
// Set up the trackBy function so that it uses the `RenderRow` as its identity by default. If
@@ -650,8 +658,8 @@ export class CdkTable<T>
650658
return this.trackBy ? this.trackBy(dataRow.dataIndex, dataRow.data) : dataRow;
651659
});
652660

653-
if (this._virtualScrollViewport) {
654-
this._setupVirtualScrolling(this._virtualScrollViewport);
661+
if (this._virtualScrollEnabled()) {
662+
this._setupVirtualScrolling(this._virtualScrollViewport!);
655663
}
656664
}
657665

@@ -668,7 +676,7 @@ export class CdkTable<T>
668676

669677
ngAfterContentInit() {
670678
this._viewRepeater =
671-
this.recycleRows || this._virtualScrollViewport
679+
this.recycleRows || this._virtualScrollEnabled()
672680
? new _RecycleViewRepeaterStrategy()
673681
: new _DisposeViewRepeaterStrategy();
674682
this._hasInitialized = true;
@@ -1629,6 +1637,10 @@ export class CdkTable<T>
16291637
const endRect = lastNode?.getBoundingClientRect?.();
16301638
return startRect && endRect ? endRect.bottom - startRect.top : 0;
16311639
}
1640+
1641+
private _virtualScrollEnabled(): boolean {
1642+
return !this._disableVirtualScrolling && this._virtualScrollViewport != null;
1643+
}
16321644
}
16331645

16341646
/** Utility function that gets a merged list of the entries in an array and values of a Set. */

0 commit comments

Comments
 (0)