Scroller and stateSave problem (Bug report with fix)
Scroller and stateSave problem (Bug report with fix)

Hello,
when you use Scroller with state saving, Scroller saves the current position (pixel and row) on every scroll. However, the starting position is only saved on every draw. This can lead to an inconsistent state.
Example: http://live.datatables.net/tahulule/1/edit
This example is the Scroller server side example with added stateSave: true
option.
To reproduce:
1. Scroll to an arbitrary position
2. Scroll a bit further (NOT triggering a redraw)
3. Reload
4. Scroll a bit further (NOT triggering a redraw)
5. Reload
Effect: After the second reload, or maybe third if you didn't scroll far, you will see an empty display.
The reason is that start
in the saved state is never updated, so iScrollerTopRow
will grow beyond start + length
. Also note, that Scroller uses topRowFloat
(derived from iScrollerTopRow
) to determine when redrawing is needed which does not reflect the real table display (controlled by _iDisplayStart
).
I believe the most appropriate fix for this problem is to always save a consistent state, ie. when saving a state with updated iScrollerTopRow
, the start
(determined by _iDisplayStart
) should also be updated.
See my implementation of _fnScroll
including the fix:
https://gist.github.com/ypnos-web/86809c58f6762eeffed29bcb960b128f
(The gist contains first the code, then a diff)
I provide my changes to you as public domain.
Thank you for your great work on DataTables!
Best,
Johannes