Scroller with bStateSave/bServerSide/sAjaxSource

Scroller with bStateSave/bServerSide/sAjaxSource

bschooleybschooley Posts: 1Questions: 0Answers: 0
edited January 2013 in Plug-ins
The scroll position isn't restored from bStateSave when using dataTables 1.9.4 with scroller 1.1.0 or 1.1.1.dev.

In the following code from scroller's _fnDrawCallback, the function is only called once and has an iDraw of 1. So the setTimeout portion never executes. Not sure if this is due to bServerSide or some change that caused only one draw to occur, but changing this if to just (this.s.dt.iDraw == 1) fixed the problem for me and I've seen no side effects so far.

The info does briefly start as 1 to x before flashing to the correct value. Perhaps it needs some type of check to have it not display until after the ajax call?

[code]
/* Restore the scrolling position that was saved by DataTable's state saving
* Note that this is done on the second draw when data is Ajax sourced, and the
* first draw when DOM soured
*/
if ( this.s.dt.oFeatures.bStateSave && this.s.dt.oLoadedState !== null &&
typeof this.s.dt.oLoadedState.iScroller != 'undefined' )
{
if ( (this.s.dt.sAjaxSource !== null && this.s.dt.iDraw == 2) ||
(this.s.dt.sAjaxSource === null && this.s.dt.iDraw == 1) )
{
setTimeout( function () {
$(that.dom.scroller).scrollTop( that.s.dt.oLoadedState.iScroller );
that.s.redrawTop = that.s.dt.oLoadedState.iScroller - (that.s.viewportHeight/2);
}, 0 );
}
}
[/code]

Replies

  • allanallan Posts: 63,679Questions: 1Answers: 10,498 Site admin
    I think it will be due to bServerSide since DataTables effectively does an 'empty' draw while the Ajax data is being fetched.

    This change looks good to me. I'll test it out a bit and merge it in later on :-)

    Thanks for posting this!

    Allan
This discussion has been closed.