rintoj / ngx-virtual-scroller

Virtual Scroll displays a virtual, "infinite" list.
https://rintoj.github.io/ngx-virtual-scroller
MIT License
978 stars 294 forks source link

Display at most a fixed number of items without specifying the container's height #291

Open npacucci opened 5 years ago

npacucci commented 5 years ago

Hi guys, I'd like to know if it is possible to tell the virtual-scroller to display only a maximum number of items inside of it, without specifiying any container height.

For example: I'm displaying a search's results inside of a virtual-scroll container, but I don't want to fix the container's height because I don't know how many results there will be, plus I don't know the height of the items containing the result. I would like to tell the virtual-scroller to display only max 10 items at a time.

Thanks in advance :)

speige commented 5 years ago

Currently the component does not support this feature. I can't think of any easy hack. If you want this, it'd have to be coded as an officially supported option in the component. I don't have time to code this right now, but if you're interested in coding it, I'm happy to accept a pull request.

The internal code of the component measures the dimensions of every child item, so theoretically it wouldn't be too hard to have the component resize itself to fit 10 items. I think it would work well for fixed size children, however, I think variable sized children could feel awkward. The reason is that variable sized children would cause the virtual-scroller would change size constantly as you scrolled.

Good luck!