From 5d91d5e81a161ebd0d15680c4ed1c92c9c70655b Mon Sep 17 00:00:00 2001 From: Mottie Date: Mon, 3 Mar 2014 18:07:14 -0600 Subject: [PATCH] Pager: ensure empty array & array of empty strings evaluates as the same. Fixes #202 --- addons/pager/jquery.tablesorter.pager.js | 4 ++++ js/widgets/widget-pager.js | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/addons/pager/jquery.tablesorter.pager.js b/addons/pager/jquery.tablesorter.pager.js index a09b792d..11c489f5 100644 --- a/addons/pager/jquery.tablesorter.pager.js +++ b/addons/pager/jquery.tablesorter.pager.js @@ -491,6 +491,10 @@ pg = Math.min( p.totalPages, p.filteredPages ); if ( p.page < 0 ) { p.page = 0; } if ( p.page > ( pg - 1 ) && pg !== 0 ) { p.page = pg - 1; } + // fixes issue where one currentFilter is [] and the other is ['','',''], + // making the next if comparison think the filters are different (joined by commas). Fixes #202. + l.currentFilters = (l.currentFilters || []).join('') === '' ? [] : l.currentFilters; + p.currentFilters = (p.currentFilters || []).join('') === '' ? [] : p.currentFilters; // don't allow rendering multiple times on the same page/size/totalpages/filters/sorts if ( l.page === p.page && l.size === p.size && l.totalPages === p.totalPages && (l.currentFilters || []).join(',') === (p.currentFilters || []).join(',') && diff --git a/js/widgets/widget-pager.js b/js/widgets/widget-pager.js index ebb7281d..3dbd77cd 100644 --- a/js/widgets/widget-pager.js +++ b/js/widgets/widget-pager.js @@ -687,6 +687,10 @@ tsp = ts.pager = { pg = Math.min( p.totalPages, p.filteredPages ); if ( p.page < 0 ) { p.page = 0; } if ( p.page > ( pg - 1 ) && pg !== 0 ) { p.page = pg - 1; } + // fixes issue where one current filter is [] and the other is ['','',''], + // making the next if comparison think the filters as different. Fixes #202. + l.currentFilters = (l.currentFilters || []).join('') === '' ? [] : l.currentFilters; + p.currentFilters = (p.currentFilters || []).join('') === '' ? [] : p.currentFilters; // don't allow rendering multiple times on the same page/size/totalpages/filters/sorts if ( l.page === p.page && l.size === p.size && l.totalPages === p.totalPages && (l.currentFilters || []).join(',') === (p.currentFilters || []).join(',') &&