Closed JosephSilber closed 5 years ago
I think this can be done using today's API. Roughly, it would be something like:
updateChild
render those dummy items in such a way as to give the approximately right height for them.scroller.scrollToIndex(desiredIndex)
.Maybe we should have a demo showing this?
So if I'm starting at record 1,000,000,000 then I'd have to create such a huge array (with empty elements)?
No, that's the beauty of the ItemSource API! It never asks you to translate indices into items until it's ready to display them.
Take a look at smoke/infinite/index.html as an example:
virtualScroller.itemSource = new ItemSource({
getLength: () => Number.MAX_SAFE_INTEGER,
item: (index) => index,
key: (index) => index,
});
// Here you can add this to scroll to the middle of the scroller
// Wait for first rendering, then scroll to middle
requestAnimationFrame(() => {
virtualScroller.scrollToIndex(virtualScroller.itemSource.length / 2);
});
Note that in this particular example, we're rendering way too many items and we hit the browser limitation on maximum height for a layer, which is ~30M pixels in chrome. That's why you'll see the scrollbar position already at the end, even though we scrolled to the middle. Try lowering the getLegth() to 1000 to see it working as expected
We're still at least loading the first set of items, no?
Yeah, if you do the requestAnimationFrame, it will load and render the first set first. You could also omit the requestAnimationFrame, and then it wouldn't load/render the first set of items.
Closing this as this seems to be solved already?
When scrolling huge lists that are incrementally being loaded from the server, there may be a need to actually start in the middle of the list.
Should there be a way to specify that we're in the middle of the list, and allow the user to scroll up to load the previous records?