mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
Pager-custom-controls: Allow setting ends and/or aroundCurrent to zero. See #1276
This commit is contained in:
parent
a42e762eda
commit
a4ad8fd7b3
@ -35,32 +35,24 @@ $.tablesorter.customPagerControls = function(settings) {
|
||||
$table = $(options.table),
|
||||
$pager = $(options.pager);
|
||||
|
||||
function validate(val, min, max) {
|
||||
if (val < min) { return min; }
|
||||
if (val > max) { return max; }
|
||||
return val;
|
||||
}
|
||||
|
||||
$table
|
||||
.on('pagerInitialized pagerComplete', function (e, c) {
|
||||
var indx,
|
||||
p = c.pager ? c.pager : c, // using widget
|
||||
pages = $('<div/>'),
|
||||
cur = p.page + 1,
|
||||
pageArray = [cur],
|
||||
pageArray = [],
|
||||
max = p.filteredPages,
|
||||
around = options.aroundCurrent,
|
||||
start = validate(cur > 1 ? (max - cur < around ? -(around + 1) + (max - cur) : -around) : 0, 0, max),
|
||||
end = validate(cur < around + 1 ? around + 3 - cur : around + 1, 0, max);
|
||||
for (indx = start; indx < end; indx++) {
|
||||
if (cur + indx >= 1 && cur + indx < max) {
|
||||
around = options.aroundCurrent;
|
||||
for (indx = -around; indx <= around; indx++) {
|
||||
if (cur + indx >= 1 && cur + indx <= max) {
|
||||
pageArray.push(cur + indx);
|
||||
}
|
||||
}
|
||||
if (pageArray.length) {
|
||||
// include first and last pages (ends) in the pagination
|
||||
for (indx = 0; indx < options.ends; indx++) {
|
||||
if ((indx + 1 < max) && $.inArray(indx + 1, pageArray) === -1) {
|
||||
if ((indx + 1 <= max) && $.inArray(indx + 1, pageArray) === -1) {
|
||||
pageArray.push(indx + 1);
|
||||
}
|
||||
if ((max - indx > 0) && $.inArray(max - indx, pageArray) === -1) {
|
||||
@ -74,7 +66,8 @@ $.tablesorter.customPagerControls = function(settings) {
|
||||
return $.inArray(value, pageArray) === key;
|
||||
});
|
||||
// make links and spacers
|
||||
if (pageArray.length > 1) {
|
||||
if (pageArray.length) {
|
||||
max = pageArray.length - 1;
|
||||
$.each(pageArray, function(indx, value) {
|
||||
pages
|
||||
.append( $(options.link.replace(/\{page\}/g, value)).toggleClass(options.currentClass, value === cur).attr('data-page', value) )
|
||||
@ -101,7 +94,8 @@ $.tablesorter.customPagerControls = function(settings) {
|
||||
})
|
||||
.end()
|
||||
.on('click', options.currentPage, function() {
|
||||
var $el =$(this)
|
||||
var $el = $(this);
|
||||
$el
|
||||
.addClass(options.currentClass)
|
||||
.siblings()
|
||||
.removeClass(options.currentClass);
|
||||
|
Loading…
Reference in New Issue
Block a user