From 07f9dd9f60224a96808aafec248b9193c81f4fbb Mon Sep 17 00:00:00 2001 From: Rob Garrison Date: Tue, 11 Apr 2017 14:57:33 -0500 Subject: [PATCH] Pager: use equalFilters for comparison. See #1384 --- addons/pager/jquery.tablesorter.pager.js | 12 ++++++++---- js/widgets/widget-pager.js | 11 ++++++++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/addons/pager/jquery.tablesorter.pager.js b/addons/pager/jquery.tablesorter.pager.js index a82facc8..5cff4d16 100644 --- a/addons/pager/jquery.tablesorter.pager.js +++ b/addons/pager/jquery.tablesorter.pager.js @@ -968,11 +968,15 @@ .unbind( pagerEvents.split(' ').join(namespace + ' ').replace(/\s+/g, ' ') ) .bind('filterInit filterStart '.split(' ').join(namespace + ' '), function(e, filters) { p.currentFilters = $.isArray(filters) ? filters : c.$table.data('lastSearch'); + var filtersEqual; + if (ts.filter.equalFilters) { + filtersEqual = ts.filter.equalFilters(c, c.lastSearch, p.currentFilters); + } else { + // will miss filter changes of the same value in a different column, see #1363 + filtersEqual = (c.lastSearch || []).join('') !== (p.currentFilters || []).join(''); + } // don't change page if filters are the same (pager updating, etc) - if ( - e.type === 'filterStart' && - p.pageReset !== false && - (c.lastSearch || []).join(',') !== (p.currentFilters || []).join(',')) { + if (e.type === 'filterStart' && p.pageReset !== false && !filtersEqual) { p.page = p.pageReset; // fixes #456 & #565 } }) diff --git a/js/widgets/widget-pager.js b/js/widgets/widget-pager.js index b57978f0..0d1fe4e5 100644 --- a/js/widgets/widget-pager.js +++ b/js/widgets/widget-pager.js @@ -249,10 +249,15 @@ .off( namespace ) .on( 'filterInit filterStart '.split( ' ' ).join( namespace + ' ' ), function( e, filters ) { p.currentFilters = $.isArray( filters ) ? filters : c.$table.data( 'lastSearch' ); + var filtersEqual; + if (ts.filter.equalFilters) { + filtersEqual = ts.filter.equalFilters(c, c.lastSearch, p.currentFilters); + } else { + // will miss filter changes of the same value in a different column, see #1363 + filtersEqual = ( c.lastSearch || [] ).join( '' ) !== ( p.currentFilters || [] ).join( '' ); + } // don't change page if filters are the same (pager updating, etc) - if ( e.type === 'filterStart' && wo.pager_pageReset !== false && - ( c.lastSearch || [] ).join( ',' ) !== ( p.currentFilters || [] ).join( ',' ) - ) { + if ( e.type === 'filterStart' && wo.pager_pageReset !== false && !filtersEqual ) { p.page = wo.pager_pageReset; // fixes #456 & #565 } })