EvHaus / doby-grid

An HTML table element on steroids.
Other
14 stars 5 forks source link

Add option to fetch extra results in remote fetch #163

Closed mminer closed 9 years ago

mminer commented 9 years ago

This makes it possible for the user to scroll through remotely fetched results without seeing blank cells that are waiting to load (requested in issue #138). It accomplishes this by fetching extra rows, the amount of which is configurable by the developer.

By default, no extra results are fetched and the behaviour remains the same as before. Set the rowsToPrefetch option to a value greater than zero to turn on prefetching. In the Remote Data example I set it to prefetch 20 rows, which I found feels good. Scrolling at a reasonably slow, steady pace doesn't show the loading spinner while a faster one does.

Additionally, I pass an extra argument to the fetcher's onLoading callback to indicate if any rows being loaded are currently visible. If they are, you probably want to display a loading indicator. If they aren't (i.e. in the best case scenario when you're "beating" the user and successfully fetching results before they scroll to them), the user need not know that requests are being made in the background on their behalf. I modified the Remote Data example to demonstrate this behaviour.

The appropriate number of rows to prefetch will depend on the speed of the AJAX request. If a remote fetch has a lot of overhead, grabbing extra results while you're making the request might be desirable. On the other hand, each individual fetch might be slower due to returning extra rows. This is especially true on the first load — if you set it to prefetch 300 rows but only 20 are initially visible, that's a lot of extra data to wait for at the start. However, the user can then scroll freely for a while before reaching rows that have yet to be fetched. It's a balancing act.