Scroller: save scroll positioning. Fixes #926 & #932

This commit is contained in:
Mottie 2015-06-21 11:11:16 -05:00
parent a8fb9614e6
commit 2adda8d2e9
2 changed files with 18 additions and 11 deletions

File diff suppressed because one or more lines are too long

View File

@ -199,6 +199,7 @@ ts.scroller = {
c.widthFixed = true; c.widthFixed = true;
wo.scroller_calcWidths = []; wo.scroller_calcWidths = [];
wo.scroller_saved = [ 0, 0 ];
wo.scroller_isBusy = true; wo.scroller_isBusy = true;
// set scrollbar width & allow setting width to zero // set scrollbar width & allow setting width to zero
@ -282,19 +283,22 @@ ts.scroller = {
$table $table
.off( namespace ) .off( namespace )
.on( 'sortEnd' + namespace, function() { .on( 'sortEnd filterEnd'.split( ' ' ).join( namespace + ' ' ), function( event ) {
// Sorting, so scroll to top // Sorting, so scroll to top
if ( wo.scroller_upAfterSort ) { if ( event.type === 'sortEnd' && wo.scroller_upAfterSort ) {
$table.parent().animate({ $tableWrap.animate({
scrollTop : 0 scrollTop : 0
}, 'fast' ); }, 'fast' );
} else if ( wo.scroller_fixedColumns ) {
setTimeout( function() {
// restore previous scroll position
$tableWrap
.scrollTop( wo.scroller_saved[1] )
.scrollLeft( wo.scroller_saved[0] );
tsScroller.updateFixed( c, wo, false );
}, 0 );
} }
}) })
.on( 'sortEnd filterEnd'.split( ' ' ).join( namespace + ' ' ), function(e) {
setTimeout(function(){
$tableWrap.trigger( 'scroll' );
}, 0);
})
.on( 'setFixedColumnSize' + namespace, function( event, size ) { .on( 'setFixedColumnSize' + namespace, function( event, size ) {
var $wrap = wo.scroller_$container; var $wrap = wo.scroller_$container;
if ( typeof size !== 'undefined' && !isNaN( size ) ) { if ( typeof size !== 'undefined' && !isNaN( size ) ) {
@ -553,7 +557,9 @@ ts.scroller = {
// using flags to prevent firing the scroll event excessively leading to slow scrolling in Firefox // using flags to prevent firing the scroll event excessively leading to slow scrolling in Firefox
if ( fixedScroll || !( tsScroller.isFirefox || tsScroller.isIE ) ) { if ( fixedScroll || !( tsScroller.isFirefox || tsScroller.isIE ) ) {
tableScroll = false; tableScroll = false;
$fixedTbody[0].scrollTop = $( this ).scrollTop(); var $this = $( this );
$fixedTbody[0].scrollTop = wo.scroller_saved[1] = $this.scrollTop();
wo.scroller_saved[0] = $this.scrollLeft();
setTimeout( function() { setTimeout( function() {
tableScroll = true; tableScroll = true;
}, 20 ); }, 20 );
@ -566,7 +572,8 @@ ts.scroller = {
// using flags to prevent firing the scroll event excessively leading to slow scrolling in Firefox // using flags to prevent firing the scroll event excessively leading to slow scrolling in Firefox
if ( tableScroll || !( tsScroller.isFirefox || tsScroller.isIE ) ) { if ( tableScroll || !( tsScroller.isFirefox || tsScroller.isIE ) ) {
fixedScroll = false; fixedScroll = false;
c.$table.parent()[0].scrollTop = $( this ).scrollTop(); var $this = $( this );
c.$table.parent()[0].scrollTop = wo.scroller_saved[1] = $this.scrollTop();
setTimeout( function() { setTimeout( function() {
fixedScroll = true; fixedScroll = true;
}, 20 ); }, 20 );