bug(cdkTable): virtual scroll does not work for tables with cdkRowDefWhen
Is this a regression?
- [ ] Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
No response
Description
Virtual scroll does not work for tables with multiple cdkRow definitions. Properties remain undefined when a line from another definition is reused.
Reproduction
StackBlitz link: cdk-table-virtual-scroll-example Steps to reproduce:
- download and update the project to Angular 21.1 (sorry, I struggled with updating on StackBlitz)
- run the project and scroll the tables down
Expected Behavior
See the lines as if there were no virtual scroll.
Actual Behavior
Rows that have reused a row of the other definition doesn't show their property. It is undefined.
Environment
- Angular: 21.1.0
- CDK/Material: 21.1.0
- Browser(s):
- Operating System (e.g. Windows, macOS, Ubuntu):
I suspect that supporting it will be tricky, given that we reuse rows. That being said, we should at least warn/error if it's used.
It would be great to have this supported also for tables with multiple row templates / conditional rows. Or maybe at least a variant which supports such tables, even if not that performant or optimized as the current feature which only works with "simple" tables.
I'll leave this issue open as a feature request so we can revisit the error at some point or if someone wants to send a PR for it.
Hi, I’m interested in working on this issue for GSoC preparation. Is it okay if I investigate and submit a PR? Any guidance would be helpful.
And it doesnt work if table in a templateoutlet. Like that :
<cdk-virtual-scroll-viewport class="example-container" [itemSize]="52" [maxBufferPx]="1200" [minBufferPx]="400">
<ng-container [ngTemplateOutlet]="tableTpl" />
</cdk-virtual-scroll-viewport>
@crisbeto What if allowed users to set this._viewRepeater.viewCacheSize = 0? Either via input or simply hardcode it for virtual scroll?