Pager: custom controls example updated to work with pager widget. Fixes #631

This commit is contained in:
Mottie 2014-05-28 11:14:37 -05:00
parent d654a18b70
commit 386d6ab5af
3 changed files with 11 additions and 7 deletions

View File

@ -97,6 +97,7 @@
<p class="tip">
<em>NOTE!</em>
<ul>
<li>Modified in <span class="version">v2.17.1</span> to properly work with either the pager addon or pager widget.</li>
<li>In <span class="version">v2.16.4</span>, code was updated to correctly count process pages.</li>
</ul>
</p>

View File

@ -36,18 +36,21 @@ $.tablesorter.customPagerControls = function(settings) {
$table
.on('pagerInitialized pagerComplete', function (e, c) {
var indx, pages = $('<div/>'), pageArray = [],
cur = c.page + 1,
start = cur > 1 ? (c.filteredPages - cur < options.aroundCurrent ? -(options.aroundCurrent + 1) + (c.filteredPages - cur) : -options.aroundCurrent) : 0,
end = cur < options.aroundCurrent + 1 ? options.aroundCurrent + 3 - cur : options.aroundCurrent + 1;
var indx,
p = c.pager ? c.pager : c, // using widget
pages = $('<div/>'),
pageArray = [],
cur = p.page + 1,
start = cur > 1 ? (p.filteredPages - cur < options.aroundCurrent ? -(options.aroundCurrent + 1) + (p.filteredPages - cur) : -options.aroundCurrent) : 0,
end = cur < options.aroundCurrent + 1 ? options.aroundCurrent + 3 - cur : options.aroundCurrent + 1;
for (indx = start; indx < end; indx++) {
if (cur + indx >= 1 && cur + indx < c.filteredPages) { pageArray.push( cur + indx ); }
if (cur + indx >= 1 && cur + indx < p.filteredPages) { pageArray.push( cur + indx ); }
}
if (pageArray.length) {
// include first and last pages (ends) in the pagination
for (indx = 0; indx < options.ends; indx++){
if ($.inArray(indx + 1, pageArray) === -1) { pageArray.push(indx + 1); }
if ($.inArray(c.filteredPages - indx, pageArray) === -1) { pageArray.push(c.filteredPages - indx); }
if ($.inArray(p.filteredPages - indx, pageArray) === -1) { pageArray.push(p.filteredPages - indx); }
}
// sort the list
pageArray = pageArray.sort(function(a, b){ return a - b; });

View File

@ -532,7 +532,7 @@
<h4>Work-in-progress</h4>
<ul>
<li><span class="label label-info">Beta</span> <a href="../beta-testing/example-pager-custom-controls.html">Custom pager control script</a></li>
<li><span class="label label-info">Beta</span> <a href="../beta-testing/example-pager-custom-controls.html">Custom pager control script</a> (<span class="version updated">v2.17.1</span>)</li>
<li><span class="label label-info">Alpha</span> <a href="../beta-testing/example-widget-column-reorder.html">Column reorder widget</a> - not working 100% with sticky headers</li>
</ul>