I am currently implementing a large, lazily rendered grid, with the goal of being able to display many more rows and columns than you could if you just rendered them directly. To do so, I've implemented a solution where:
- The grid is a container div that holds a
scrollerandcontentdiv. Thescrollerdiv is empty, and thecontentdiv displays whatever is visible on the screen. - The user scrolls in the container by scrolling the
scroller. - Based on where the
scrollerdiv is, thecontentdiv renders different data for the content. - The
contentdiv translates itself around so that it stays positioned correctly.
Functionally, this allows us to render very few divs, while from the users perspective, they can scroll through their data as normal. This is necessary, given the data sizes I'm working with.
However, I need to be able to scroll the grid to a specific location (e.g. the 100th row, 3rd column). To do so, I need to be able to move the scroller div. However, as most of scroller div is hidden (by the grid container), I cannot figure out how to use the scroll or scrollBy functions to accomplish this. As the scroller element is mostly hidden, the scroll function cannot move it, as scroll only works in relation to the visible aspect of the element (I think!).
I striped down the grid to the minimal reproducible example in the codepen here: https://codepen.io/naterush/pen/WNOZGze (it was too big to be reasonable to put in this question). This just has a single row of data, and you can scroll to the right inside of it to see more data.
The only code that needs to be finished is the scrollTo20 function. Any thoughts or comments or directions would be greatly appreciated!