From 1b43b0401578e7b4fa1412df955b963ae4b5f620 Mon Sep 17 00:00:00 2001
From: Rob Garrison
Date: Fri, 30 Dec 2016 16:52:19 -0600
Subject: [PATCH] Pager: add data-attribute override on output. See #1348
---
addons/pager/jquery.tablesorter.pager.js | 10 +++++++---
docs/example-pager.html | 16 +++++++++-------
docs/example-widget-pager.html | 18 +++++++++---------
docs/index.html | 12 ++++++++----
js/widgets/widget-pager.js | 10 +++++++---
5 files changed, 40 insertions(+), 26 deletions(-)
diff --git a/addons/pager/jquery.tablesorter.pager.js b/addons/pager/jquery.tablesorter.pager.js
index 4550e608..afc5d273 100644
--- a/addons/pager/jquery.tablesorter.pager.js
+++ b/addons/pager/jquery.tablesorter.pager.js
@@ -173,7 +173,7 @@
updatePageDisplay = function(table, p, completed) {
if ( p.initializing ) { return; }
- var s, t, $out, $el, indx, len, options,
+ var s, t, $out, $el, indx, len, options, output,
c = table.config,
namespace = c.namespace + 'pager',
sz = parsePageSize( p, p.size, 'get' ); // don't allow dividing by zero
@@ -196,8 +196,12 @@
if (typeof p.output === 'function') {
s = p.output(table, p);
} else {
+ output = $out
+ // get output template from data-pager-output or data-pager-output-filtered
+ .attr('data-pager-output' + (p.filteredRows < p.totalRows ? '-filtered' : '')) ||
+ p.output;
// form the output string (can now get a new output string from the server)
- s = ( p.ajaxData && p.ajaxData.output ? p.ajaxData.output || p.output : p.output )
+ s = ( p.ajaxData && p.ajaxData.output ? p.ajaxData.output || output : output )
// {page} = one-based index; {page+#} = zero based index +/- value
.replace(/\{page([\-+]\d+)?\}/gi, function(m, n){
return p.totalPages ? p.page + (n ? parseInt(n, 10) : 1) : 0;
@@ -496,7 +500,7 @@
$h.find('.' + ts.css.headerIn).html( th[j] );
if (hsh && $sh.length) {
// add sticky header to container just in case it contains pager controls
- p.$container = p.$container.add( wo.$sticky );
+ p.$container = p.$container.add( c.widgetOptions.$sticky );
$sh.eq(j).find('.' + ts.css.headerIn).html( th[j] );
}
}
diff --git a/docs/example-pager.html b/docs/example-pager.html
index d4e845e8..1199834f 100644
--- a/docs/example-pager.html
+++ b/docs/example-pager.html
@@ -58,7 +58,7 @@
// also {page:input} & {startRow:input} will add a modifiable input in place of the value
// In v2.27.7, this can be set as a function
// output: function(table, pager) { return 'page ' + pager.startRow + ' - ' + pager.endRow; }
- output: '{startRow:input} to {endRow} ({totalRows})',
+ output: '{startRow:input} – {endRow} / {totalRows} rows',
// apply disabled classname (cssDisabled option) to the pager arrows when the rows
// are at either extreme is visible; default is true
@@ -116,7 +116,7 @@
.tablesorter({
theme: 'blue',
widthFixed: true,
- widgets: ['zebra']
+ widgets: ['zebra', 'filter']
})
// bind to pager events
@@ -239,6 +239,7 @@
NOTE! The following are not part of the original plugin:
+ - In v2.28.4, added
data-pager-output
and data-pager-output-filtered
attributes which override the output
option when set on the pageDisplay
element.
- In v2.26.0, a page size of "all" instead of a specific number will be saved and used on reload. Also, ajax interaction will pass a size of "all" which may break current server methods on number of pages to return.
- In v2.24.0, a page size select option with a value of "all" will display all rows - not recommended for ajax interactions!
- In v2.23.0, the following methods were changed due to issues with unique namespacing.
@@ -271,14 +272,14 @@