mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
Pager: ensure filteredRows is current on page move. See #745
This commit is contained in:
parent
0ee530de30
commit
cdaa65f041
@ -131,17 +131,10 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
updatePageDisplay = function(table, p, completed) {
|
calcFilters = function(table, p) {
|
||||||
if ( !p.initialized ) { return; }
|
var c = table.config,
|
||||||
var s, $out, regex,
|
hasFilters = c.$table.hasClass('hasFilters');
|
||||||
c = table.config,
|
if (hasFilters && !p.ajaxUrl) {
|
||||||
f = c.$table.hasClass('hasFilters'),
|
|
||||||
t = [],
|
|
||||||
sz = p.size || 10; // don't allow dividing by zero
|
|
||||||
t = [ (c.widgetOptions && c.widgetOptions.filter_filteredRow || 'filtered'), c.selectorRemove.replace(/^(\w+\.)/g,'') ];
|
|
||||||
if (p.countChildRows) { t.push(c.cssChildRow); }
|
|
||||||
regex = new RegExp( '(' + t.join('|') + ')' );
|
|
||||||
if (f && !p.ajaxUrl) {
|
|
||||||
if ($.isEmptyObject(c.cache)) {
|
if ($.isEmptyObject(c.cache)) {
|
||||||
// delayInit: true so nothing is in the cache
|
// delayInit: true so nothing is in the cache
|
||||||
p.filteredRows = p.totalRows = c.$tbodies.eq(0).children('tr').not( p.countChildRows ? '' : '.' + c.cssChildRow ).length;
|
p.filteredRows = p.totalRows = c.$tbodies.eq(0).children('tr').not( p.countChildRows ? '' : '.' + c.cssChildRow ).length;
|
||||||
@ -151,11 +144,20 @@
|
|||||||
p.filteredRows += p.regexRows.test(el[c.columns].$row[0].className) ? 0 : 1;
|
p.filteredRows += p.regexRows.test(el[c.columns].$row[0].className) ? 0 : 1;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if (!f) {
|
} else if (!hasFilters) {
|
||||||
p.filteredRows = p.totalRows;
|
p.filteredRows = p.totalRows;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
updatePageDisplay = function(table, p, completed) {
|
||||||
|
if ( !p.initialized ) { return; }
|
||||||
|
var s, t, $out,
|
||||||
|
c = table.config,
|
||||||
|
sz = p.size || 10; // don't allow dividing by zero
|
||||||
|
if (p.countChildRows) { t.push(c.cssChildRow); }
|
||||||
p.totalPages = Math.ceil( p.totalRows / sz ); // needed for "pageSize" method
|
p.totalPages = Math.ceil( p.totalRows / sz ); // needed for "pageSize" method
|
||||||
c.totalRows = p.totalRows;
|
c.totalRows = p.totalRows;
|
||||||
|
calcFilters(table, p);
|
||||||
c.filteredRows = p.filteredRows;
|
c.filteredRows = p.filteredRows;
|
||||||
p.filteredPages = Math.ceil( p.filteredRows / sz ) || 0;
|
p.filteredPages = Math.ceil( p.filteredRows / sz ) || 0;
|
||||||
if ( Math.min( p.totalPages, p.filteredPages ) >= 0 ) {
|
if ( Math.min( p.totalPages, p.filteredPages ) >= 0 ) {
|
||||||
@ -220,7 +222,7 @@
|
|||||||
// Filter the options page number link array if it's larger than 'maxOptionSize'
|
// 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
|
// 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,
|
var i, central_focus_size, focus_option_pages, insert_index, option_length, focus_length,
|
||||||
pg = Math.min( p.totalPages, p.filteredPages ),
|
pg = Math.min( p.totalPages, p.filteredPages ) || 1,
|
||||||
// make skip set size multiples of 5
|
// make skip set size multiples of 5
|
||||||
skip_set_size = Math.ceil( ( pg / p.maxOptionSize ) / 5 ) * 5,
|
skip_set_size = Math.ceil( ( pg / p.maxOptionSize ) / 5 ) * 5,
|
||||||
large_collection = pg > p.maxOptionSize,
|
large_collection = pg > p.maxOptionSize,
|
||||||
@ -646,13 +648,14 @@
|
|||||||
|
|
||||||
moveToPage = function(table, p, pageMoved) {
|
moveToPage = function(table, p, pageMoved) {
|
||||||
if ( p.isDisabled ) { return; }
|
if ( p.isDisabled ) { return; }
|
||||||
var c = table.config,
|
var pg, c = table.config,
|
||||||
$t = $(table),
|
$t = $(table),
|
||||||
l = p.last,
|
l = p.last;
|
||||||
pg = Math.min( p.totalPages, p.filteredPages ) || 1;
|
|
||||||
if ( pageMoved !== false && p.initialized && $.isEmptyObject(c.cache)) {
|
if ( pageMoved !== false && p.initialized && $.isEmptyObject(c.cache)) {
|
||||||
return updateCache(table);
|
return updateCache(table);
|
||||||
}
|
}
|
||||||
|
calcFilters(table, p);
|
||||||
|
pg = Math.min( p.totalPages, p.filteredPages );
|
||||||
if ( p.page < 0 ) { p.page = 0; }
|
if ( p.page < 0 ) { p.page = 0; }
|
||||||
if ( p.page > ( pg - 1 ) && pg !== 0 ) { p.page = pg - 1; }
|
if ( p.page > ( pg - 1 ) && pg !== 0 ) { p.page = pg - 1; }
|
||||||
// fixes issue where one currentFilter is [] and the other is ['','',''],
|
// fixes issue where one currentFilter is [] and the other is ['','',''],
|
||||||
|
@ -352,18 +352,10 @@ tsp = ts.pager = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
updatePageDisplay: function(table, c, completed) {
|
calcFilters: function(table, c) {
|
||||||
var s, $out, regex,
|
var p = c.pager,
|
||||||
wo = c.widgetOptions,
|
hasFilters = c.$table.hasClass('hasFilters');
|
||||||
p = c.pager,
|
if (hasFilters && !p.ajaxUrl) {
|
||||||
f = c.$table.hasClass('hasFilters'),
|
|
||||||
t = [],
|
|
||||||
sz = p.size || 10; // don't allow dividing by zero
|
|
||||||
t = [ wo && wo.filter_filteredRow || 'filtered', c.selectorRemove.replace(/^(\w+\.)/g,'') ];
|
|
||||||
if (wo.pager_countChildRows) { t.push(c.cssChildRow); }
|
|
||||||
regex = new RegExp( '(' + t.join('|') + ')' );
|
|
||||||
p.$size.add(p.$goto).removeClass(wo.pager_css.disabled).removeAttr('disabled').attr('aria-disabled', 'false');
|
|
||||||
if (f && !wo.pager_ajaxUrl) {
|
|
||||||
if ($.isEmptyObject(c.cache)) {
|
if ($.isEmptyObject(c.cache)) {
|
||||||
// delayInit: true so nothing is in the cache
|
// delayInit: true so nothing is in the cache
|
||||||
p.filteredRows = p.totalRows = c.$tbodies.eq(0).children('tr').not( c.widgetOptions.pager_countChildRows ? '' : '.' + c.cssChildRow ).length;
|
p.filteredRows = p.totalRows = c.$tbodies.eq(0).children('tr').not( c.widgetOptions.pager_countChildRows ? '' : '.' + c.cssChildRow ).length;
|
||||||
@ -373,11 +365,21 @@ tsp = ts.pager = {
|
|||||||
p.filteredRows += p.regexRows.test(el[c.columns].$row[0].className) ? 0 : 1;
|
p.filteredRows += p.regexRows.test(el[c.columns].$row[0].className) ? 0 : 1;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if (!f) {
|
} else if (!hasFilters) {
|
||||||
p.filteredRows = p.totalRows;
|
p.filteredRows = p.totalRows;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
updatePageDisplay: function(table, c, completed) {
|
||||||
|
var s, t, $out, regex,
|
||||||
|
wo = c.widgetOptions,
|
||||||
|
p = c.pager,
|
||||||
|
sz = p.size || 10; // don't allow dividing by zero
|
||||||
|
if (wo.pager_countChildRows) { t.push(c.cssChildRow); }
|
||||||
|
p.$size.add(p.$goto).removeClass(wo.pager_css.disabled).removeAttr('disabled').attr('aria-disabled', 'false');
|
||||||
p.totalPages = Math.ceil( p.totalRows / sz ); // needed for "pageSize" method
|
p.totalPages = Math.ceil( p.totalRows / sz ); // needed for "pageSize" method
|
||||||
c.totalRows = p.totalRows;
|
c.totalRows = p.totalRows;
|
||||||
|
tsp.calcFilters(table, c);
|
||||||
c.filteredRows = p.filteredRows;
|
c.filteredRows = p.filteredRows;
|
||||||
p.filteredPages = Math.ceil( p.filteredRows / sz ) || 0;
|
p.filteredPages = Math.ceil( p.filteredRows / sz ) || 0;
|
||||||
if ( Math.min( p.totalPages, p.filteredPages ) >= 0 ) {
|
if ( Math.min( p.totalPages, p.filteredPages ) >= 0 ) {
|
||||||
@ -878,10 +880,11 @@ tsp = ts.pager = {
|
|||||||
if ( pageMoved !== false && p.initialized && $.isEmptyObject(table.config.cache)) {
|
if ( pageMoved !== false && p.initialized && $.isEmptyObject(table.config.cache)) {
|
||||||
return tsp.updateCache(table);
|
return tsp.updateCache(table);
|
||||||
}
|
}
|
||||||
var c = table.config,
|
var pg, c = table.config,
|
||||||
wo = c.widgetOptions,
|
wo = c.widgetOptions,
|
||||||
l = p.last,
|
l = p.last
|
||||||
pg = Math.min( p.totalPages, p.filteredPages ) || 1;
|
tsp.calcFilters(table, c);
|
||||||
|
pg = Math.min( p.totalPages, p.filteredPages );
|
||||||
if ( p.page < 0 ) { p.page = 0; }
|
if ( p.page < 0 ) { p.page = 0; }
|
||||||
if ( p.page > ( pg - 1 ) && pg !== 0 ) { p.page = pg - 1; }
|
if ( p.page > ( pg - 1 ) && pg !== 0 ) { p.page = pg - 1; }
|
||||||
// fixes issue where one current filter is [] and the other is ['','',''],
|
// fixes issue where one current filter is [] and the other is ['','',''],
|
||||||
|
Loading…
Reference in New Issue
Block a user