angular / components

Component infrastructure and Material Design components for Angular
https://material.angular.io
MIT License
24.22k stars 6.69k forks source link

Virtual scroll: weird behaviour when data is set to empty #16775

Open el-meher opened 4 years ago

el-meher commented 4 years ago

What are you trying to do?

I have a virtual scroll coupled to a paginated request. At some point, the user may need to refresh the list. the new result of the query may be empty so I am setting the data to empty.

What troubleshooting steps have you tried?

The virtual scroll show only the first page after refresh

Reproduction

We can only help if we can reproduce the problem ourselves.

I tried to make a minimal example https://stackblitz.com/edit/angular-ehqgvp-b5qa5x?file=app/cdk-virtual-scroll-data-source-example.ts

Steps to reproduce:

  1. scroll over list : expected behaviour
  2. click on refresh button
  3. scroll over list : only the first page is shown

Environment

andrewseguin commented 4 years ago

It seems that when you reset cachedData, you need to re-initialize it to what you had in the beginning

https://stackblitz.com/edit/angular-ehqgvp-tu1zid?file=app/cdk-virtual-scroll-data-source-example.ts

el-meher commented 4 years ago

I investigated the problem and it seems related to FixedSizeVirtualScrollStrategy.prototype._updateRenderedRange. When the data is empty, it should set the new range to (0,0) but it doesn't. The logic behind this scroll strategy is that data could only expand, so the size of the range.