components icon indicating copy to clipboard operation
components copied to clipboard

bug(cdkTable): virtual scroll does not work for tables with cdkRowDefWhen

Open lpl14 opened this issue 10 months ago • 6 comments

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:

  1. download and update the project to Angular 21.1 (sorry, I struggled with updating on StackBlitz)
  2. 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):

lpl14 avatar Jan 18 '26 23:01 lpl14

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.

crisbeto avatar Jan 20 '26 11:01 crisbeto

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.

mkraus-mapp avatar Jan 21 '26 14:01 mkraus-mapp

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.

crisbeto avatar Jan 23 '26 06:01 crisbeto

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.

divyanshisingh987456321 avatar Jan 28 '26 08:01 divyanshisingh987456321

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>

blueiceprj avatar Apr 05 '26 05:04 blueiceprj

@crisbeto What if allowed users to set this._viewRepeater.viewCacheSize = 0? Either via input or simply hardcode it for virtual scroll?

TomaszKasowicz avatar Nov 04 '26 16:11 TomaszKasowicz