diff --git a/addons/pager/jquery.tablesorter.pager.js b/addons/pager/jquery.tablesorter.pager.js
index 1c1bd325..a50a5f5a 100644
--- a/addons/pager/jquery.tablesorter.pager.js
+++ b/addons/pager/jquery.tablesorter.pager.js
@@ -126,13 +126,13 @@
$this = this,
// hide arrows at extremes
- pagerArrows = function(p, disable) {
+ pagerArrows = function( table, p, disable ) {
var a = 'addClass',
r = 'removeClass',
d = p.cssDisabled,
dis = !!disable,
first = ( dis || p.page === 0 ),
- tp = Math.min( p.totalPages, p.filteredPages ),
+ tp = getTotalPages( table, p ),
last = ( dis || (p.page === tp - 1) || tp === 0 );
if ( p.updateArrows ) {
p.$container.find(p.cssFirst + ',' + p.cssPrev)[ first ? a : r ](d).attr('aria-disabled', first);
@@ -174,7 +174,7 @@
calcFilters(table, p);
c.filteredRows = p.filteredRows;
p.filteredPages = Math.ceil( p.filteredRows / sz ) || 0;
- if ( Math.min( p.totalPages, p.filteredPages ) >= 0 ) {
+ if ( getTotalPages( table, p ) >= 0 ) {
t = (p.size * p.page > p.filteredRows) && completed;
p.page = (t) ? p.pageReset || 0 : p.page;
p.startRow = (t) ? p.size * p.page + 1 : (p.filteredRows === 0 ? 0 : p.size * p.page + 1);
@@ -203,7 +203,7 @@
});
if ( p.$goto.length ) {
t = '';
- options = buildPageSelect(p);
+ options = buildPageSelect( table, p );
len = options.length;
for (indx = 0; indx < len; indx++) {
t += '';
@@ -221,7 +221,7 @@
});
}
}
- pagerArrows(p);
+ pagerArrows( table, p );
fixHeight(table, p);
if (p.initialized && completed !== false) {
if (c.debug) {
@@ -238,11 +238,11 @@
}
},
- buildPageSelect = function(p) {
+ buildPageSelect = function( table, p ) {
// Filter the options page number link array if it's larger than 'maxOptionSize'
// as large page set links will slow the browser on large dom inserts
var i, central_focus_size, focus_option_pages, insert_index, option_length, focus_length,
- pg = Math.min( p.totalPages, p.filteredPages ) || 1,
+ pg = getTotalPages( table, p ) || 1,
// make skip set size multiples of 5
skip_set_size = Math.ceil( ( pg / p.maxOptionSize ) / 5 ) * 5,
large_collection = pg > p.maxOptionSize,
@@ -373,7 +373,7 @@
p.size = parsePageSize( p, p.$size.val(), 'get' );
p.$size.val( parsePageSize( p, p.size, 'set' ) );
$.data(table, 'pagerLastSize', p.size);
- pagerArrows(p);
+ pagerArrows( table, p );
if ( !p.removeRows ) {
hideRows(table, p);
$(table).bind('sortEnd filterEnd '.split(' ').join(table.config.namespace + 'pager '), function(){
@@ -661,7 +661,7 @@
showAllRows = function(table, p) {
var index, $controls, len;
if ( p.ajax ) {
- pagerArrows(p, true);
+ pagerArrows( table, p, true );
} else {
$.data(table, 'pagerLastPage', p.page);
$.data(table, 'pagerLastSize', p.size);
@@ -719,7 +719,6 @@
}
// abort page move if the table has filters and has not been initialized
if (p.ajax && ts.hasWidget(table, 'filter') && !c.widgetOptions.filter_initialized) { return; }
-
parsePageNumber( table, p );
calcFilters(table, p);
// fixes issue where one currentFilter is [] and the other is ['','',''],
@@ -768,22 +767,26 @@
}
},
+ getTotalPages = function( table, p ) {
+ return ts.hasWidget( table, 'filter' ) ? Math.min( p.totalPages, p.filteredPages ) : p.totalPages;
+ },
+
// set to either set or get value
parsePageSize = function( p, size, mode ) {
var s = parseInt( size, 10 ) || p.size || p.settings.size || 10,
// if select does not contain an "all" option, use size
setAll = p.$size.find( 'option[value="all"]' ).length ? 'all' : p.totalRows;
return /all/i.test( size ) || s === p.totalRows ?
- // "get" to set `p.size` or "set" to set `p.$size.val()`
+ // "get" to get `p.size` or "set" to set `p.$size.val()`
( mode === 'get' ? p.totalRows : setAll ) :
( mode === 'get' ? s : p.size );
},
parsePageNumber = function( table, p ) {
- var min = ( ts.hasWidget( table, 'filter' ) ? Math.min( p.totalPages, p.filteredPages ) : p.totalPages ) - 1;
+ var min = getTotalPages( table, p ) - 1;
p.page = parseInt( p.page, 10 );
if ( p.page < 0 || isNaN( p.page ) ) { p.page = 0; }
- if ( p.page > min && p.page !== 0 ) { p.page = min; }
+ if ( p.page > min && min !== 0 ) { p.page = min; }
return p.page;
},
@@ -803,14 +806,15 @@
},
moveToLastPage = function(table, p) {
- p.page = ( Math.min( p.totalPages, p.filteredPages ) - 1 );
+ p.page = getTotalPages( table, p ) - 1;
moveToPage(table, p);
},
moveToNextPage = function(table, p) {
p.page++;
- if ( p.page >= ( Math.min( p.totalPages, p.filteredPages ) - 1 ) ) {
- p.page = ( Math.min( p.totalPages, p.filteredPages ) - 1 );
+ var last = getTotalPages( table, p ) - 1;
+ if ( p.page >= last ) {
+ p.page = last;
}
moveToPage(table, p);
},
@@ -855,7 +859,7 @@
size = p.$size.find('option[selected]').val();
p.size = $.data(table, 'pagerLastSize') || parsePageSize( p, p.size, 'get' );
p.$size.val( parsePageSize( p, p.size, 'set' ) ); // set page size
- p.totalPages = Math.ceil( Math.min( p.totalRows, p.filteredRows ) / p.size );
+ p.totalPages = Math.ceil( getTotalPages( table, p ) / p.size );
// if table id exists, include page display with aria info
if ( table.id ) {
info = table.id + '_pager_info';
diff --git a/dist/js/extras/jquery.tablesorter.pager.min.js b/dist/js/extras/jquery.tablesorter.pager.min.js
index 2d5ca9ce..356cdf00 100644
--- a/dist/js/extras/jquery.tablesorter.pager.min.js
+++ b/dist/js/extras/jquery.tablesorter.pager.min.js
@@ -2,4 +2,4 @@
* tablesorter (FORK) pager plugin
* updated 11/10/2015 (v2.24.5)
*/
-!function(a){"use strict";var b=a.tablesorter;a.extend({tablesorterPager:new function(){this.defaults={container:null,ajaxUrl:null,customAjaxUrl:function(a,b){return b},ajaxError:null,ajaxObject:{dataType:"json"},processAjaxOnInit:!0,ajaxProcessing:function(a){return[0,[],null]},output:"{startRow} to {endRow} of {totalRows} rows",updateArrows:!0,page:0,pageReset:0,size:10,maxOptionSize:20,savePages:!0,storageKey:"tablesorter-pager",fixedHeight:!1,countChildRows:!1,removeRows:!1,cssFirst:".first",cssPrev:".prev",cssNext:".next",cssLast:".last",cssGoto:".gotoPage",cssPageDisplay:".pagedisplay",cssPageSize:".pagesize",cssErrorRow:"tablesorter-errorRow",cssDisabled:"disabled",totalRows:0,totalPages:0,filteredRows:0,filteredPages:0,ajaxCounter:0,currentFilters:[],startRow:0,endRow:0,$size:null,last:{}};var c="filterInit filterStart filterEnd sortEnd disablePager enablePager destroyPager updateComplete pageSize pageSet pageAndSize pagerUpdate refreshComplete ",d=this,e=function(a,b){var c="addClass",d="removeClass",e=a.cssDisabled,f=!!b,g=f||0===a.page,h=Math.min(a.totalPages,a.filteredPages),i=f||a.page===h-1||0===h;a.updateArrows&&(a.$container.find(a.cssFirst+","+a.cssPrev)[g?c:d](e).attr("aria-disabled",g),a.$container.find(a.cssNext+","+a.cssLast)[i?c:d](e).attr("aria-disabled",i))},f=function(a,c){var d,e,f,g=a.config,h=g.$table.hasClass("hasFilters");if(h&&!c.ajaxUrl)if(b.isEmptyObject(g.cache))c.filteredRows=c.totalRows=g.$tbodies.eq(0).children("tr").not(c.countChildRows?"":"."+g.cssChildRow).length;else for(c.filteredRows=0,d=g.cache[0].normalized,f=d.length,e=0;f>e;e++)c.filteredRows+=c.regexRows.test(d[e][g.columns].$row[0].className)?0:1;else h||(c.filteredRows=c.totalRows)},g=function(c,d,g){if(!d.initializing){var j,k,l,m,n,o,p=c.config,q=p.namespace+"pager",r=t(d,d.size,"get");if(d.countChildRows&&k.push(p.cssChildRow),d.totalPages=Math.ceil(d.totalRows/r),p.totalRows=d.totalRows,u(c,d),f(c,d),p.filteredRows=d.filteredRows,d.filteredPages=Math.ceil(d.filteredRows/r)||0,Math.min(d.totalPages,d.filteredPages)>=0){if(k=d.size*d.page>d.filteredRows&&g,d.page=k?d.pageReset||0:d.page,d.startRow=k?d.size*d.page+1:0===d.filteredRows?0:d.size*d.page+1,d.endRow=Math.min(d.filteredRows,d.totalRows,d.size*(d.page+1)),l=d.$container.find(d.cssPageDisplay),j=(d.ajaxData&&d.ajaxData.output?d.ajaxData.output||d.output:d.output).replace(/\{page([\-+]\d+)?\}/gi,function(a,b){return d.totalPages?d.page+(b?parseInt(b,10):1):0}).replace(/\{\w+(\s*:\s*\w+)?\}/gi,function(a){var b,c,e=a.replace(/[{}\s]/g,""),f=e.split(":"),g=d.ajaxData,h=/(rows?|pages?)$/i.test(e)?0:"";return/(startRow|page)/.test(f[0])&&"input"===f[1]?(b=(""+("page"===f[0]?d.totalPages:d.totalRows)).length,c="page"===f[0]?d.page+1:d.startRow,''):f.length>1&&g&&g[f[0]]?g[f[0]][f[1]]:d[e]||(g?g[e]:h)||h}),d.$goto.length){for(k="",o=h(d),n=o.length,m=0;n>m;m++)k+='";d.$goto.html(k).val(d.page+1)}l.length&&(l["INPUT"===l[0].nodeName?"val":"html"](j),l.find(".ts-startRow, .ts-page").unbind("change"+q).bind("change"+q,function(){var b=a(this).val(),c=a(this).hasClass("ts-startRow")?Math.floor(b/d.size)+1:b;p.$table.trigger("pageSet"+q,[c])}))}e(d),i(c,d),d.initialized&&g!==!1&&(p.debug&&console.log("Pager: Triggering pagerComplete"),p.$table.trigger("pagerComplete",d),d.savePages&&b.storage&&b.storage(c,d.storageKey,{page:d.page,size:d.size}))}},h=function(b){var c,d,e,f,g,h,i=Math.min(b.totalPages,b.filteredPages)||1,j=5*Math.ceil(i/b.maxOptionSize/5),k=i>b.maxOptionSize,l=b.page+1,m=j,n=i-j,o=[1],p=k?j:1;for(c=p;i>=c;)o.push(c),c+=k?j:1;if(o.push(i),k){for(e=[],d=Math.max(Math.floor(b.maxOptionSize/j)-1,5),m=l-d,1>m&&(m=1),n=l+d,n>i&&(n=i),c=m;n>=c;c++)e.push(c);o=a.grep(o,function(b,c){return a.inArray(b,o)===c}),g=o.length,h=e.length,g-h>j/2&&g+h>b.maxOptionSize&&(f=Math.floor(g/2)-Math.floor(h/2),Array.prototype.splice.apply(o,[f,h])),o=o.concat(e)}return o=a.grep(o,function(b,c){return a.inArray(b,o)===c}).sort(function(a,b){return a-b})},i=function(b,c){var d,e,f=b.config,g=f.$tbodies.eq(0);g.find("tr.pagerSavedHeightSpacer").remove(),c.fixedHeight&&!c.isDisabled&&(e=a.data(b,"pagerSavedHeight"),e&&(d=e-g.height(),d>5&&a.data(b,"pagerLastSize")===c.size&&g.children("tr:visible").length