2012-11-28 02:55:36 +00:00
|
|
|
/*!
|
2016-06-08 12:52:57 +00:00
|
|
|
* tablesorter (FORK) pager plugin
|
2016-06-29 22:34:21 +00:00
|
|
|
* updated 6/28/2016 (v2.26.5)
|
2016-06-08 12:52:57 +00:00
|
|
|
*/
|
2012-11-28 02:55:36 +00:00
|
|
|
/*jshint browser:true, jquery:true, unused:false */
|
|
|
|
;(function($) {
|
2015-07-23 04:29:51 +00:00
|
|
|
'use strict';
|
2012-12-18 21:50:42 +00:00
|
|
|
/*jshint supernew:true */
|
2013-10-03 12:27:23 +00:00
|
|
|
var ts = $.tablesorter;
|
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
$.extend({
|
|
|
|
tablesorterPager: new function() {
|
|
|
|
|
|
|
|
this.defaults = {
|
|
|
|
// target the pager markup
|
|
|
|
container: null,
|
|
|
|
|
|
|
|
// use this format: "http://mydatabase.com?page={page}&size={size}&{sortList:col}&{filterList:fcol}"
|
|
|
|
// where {page} is replaced by the page number, {size} is replaced by the number of records to show,
|
|
|
|
// {sortList:col} adds the sortList to the url into a "col" array, and {filterList:fcol} adds
|
|
|
|
// the filterList to the url into an "fcol" array.
|
|
|
|
// So a sortList = [[2,0],[3,0]] becomes "&col[2]=0&col[3]=0" in the url
|
|
|
|
// and a filterList = [[2,Blue],[3,13]] becomes "&fcol[2]=Blue&fcol[3]=13" in the url
|
|
|
|
ajaxUrl: null,
|
|
|
|
|
|
|
|
// modify the url after all processing has been applied
|
|
|
|
customAjaxUrl: function(table, url) { return url; },
|
|
|
|
|
|
|
|
// ajax error callback from $.tablesorter.showError function
|
|
|
|
// ajaxError: function( config, xhr, settings, exception ){ return exception; };
|
|
|
|
// returning false will abort the error message
|
|
|
|
ajaxError: null,
|
|
|
|
|
|
|
|
// modify the $.ajax object to allow complete control over your ajax requests
|
|
|
|
ajaxObject: {
|
|
|
|
dataType: 'json'
|
|
|
|
},
|
|
|
|
|
|
|
|
// set this to false if you want to block ajax loading on init
|
|
|
|
processAjaxOnInit: true,
|
|
|
|
|
|
|
|
// process ajax so that the following information is returned:
|
|
|
|
// [ total_rows (number), rows (array of arrays), headers (array; optional) ]
|
|
|
|
// example:
|
|
|
|
// [
|
|
|
|
// 100, // total rows
|
|
|
|
// [
|
|
|
|
// [ "row1cell1", "row1cell2", ... "row1cellN" ],
|
|
|
|
// [ "row2cell1", "row2cell2", ... "row2cellN" ],
|
|
|
|
// ...
|
|
|
|
// [ "rowNcell1", "rowNcell2", ... "rowNcellN" ]
|
|
|
|
// ],
|
|
|
|
// [ "header1", "header2", ... "headerN" ] // optional
|
|
|
|
// ]
|
|
|
|
ajaxProcessing: function(ajax){ return [ 0, [], null ]; },
|
|
|
|
|
|
|
|
// output default: '{page}/{totalPages}'
|
|
|
|
// possible variables: {size}, {page}, {totalPages}, {filteredPages}, {startRow},
|
|
|
|
// {endRow}, {filteredRows} and {totalRows}
|
|
|
|
output: '{startRow} to {endRow} of {totalRows} rows', // '{page}/{totalPages}'
|
|
|
|
|
|
|
|
// apply disabled classname to the pager arrows when the rows at either extreme is visible
|
|
|
|
updateArrows: true,
|
|
|
|
|
|
|
|
// starting page of the pager (zero based index)
|
|
|
|
page: 0,
|
|
|
|
|
|
|
|
// reset pager after filtering; set to desired page #
|
|
|
|
// set to false to not change page at filter start
|
|
|
|
pageReset: 0,
|
|
|
|
|
|
|
|
// Number of visible rows
|
|
|
|
size: 10,
|
|
|
|
|
|
|
|
// Number of options to include in the pager number selector
|
|
|
|
maxOptionSize: 20,
|
|
|
|
|
|
|
|
// Save pager page & size if the storage script is loaded (requires $.tablesorter.storage in jquery.tablesorter.widgets.js)
|
|
|
|
savePages: true,
|
|
|
|
|
|
|
|
// defines custom storage key
|
|
|
|
storageKey: 'tablesorter-pager',
|
|
|
|
|
|
|
|
// if true, the table will remain the same height no matter how many records are displayed. The space is made up by an empty
|
|
|
|
// table row set to a height to compensate; default is false
|
|
|
|
fixedHeight: false,
|
|
|
|
|
|
|
|
// count child rows towards the set page size? (set true if it is a visible table row within the pager)
|
|
|
|
// if true, child row(s) may not appear to be attached to its parent row, may be split across pages or
|
|
|
|
// may distort the table if rowspan or cellspans are included.
|
|
|
|
countChildRows: false,
|
|
|
|
|
|
|
|
// remove rows from the table to speed up the sort of large tables.
|
|
|
|
// setting this to false, only hides the non-visible rows; needed if you plan to add/remove rows with the pager enabled.
|
|
|
|
removeRows: false, // removing rows in larger tables speeds up the sort
|
|
|
|
|
|
|
|
// css class names of pager arrows
|
|
|
|
cssFirst: '.first', // go to first page arrow
|
|
|
|
cssPrev: '.prev', // previous page arrow
|
|
|
|
cssNext: '.next', // next page arrow
|
|
|
|
cssLast: '.last', // go to last page arrow
|
|
|
|
cssGoto: '.gotoPage', // go to page selector - select dropdown that sets the current page
|
|
|
|
cssPageDisplay: '.pagedisplay', // location of where the "output" is displayed
|
|
|
|
cssPageSize: '.pagesize', // page size selector - select dropdown that sets the "size" option
|
|
|
|
cssErrorRow: 'tablesorter-errorRow', // error information row
|
|
|
|
|
|
|
|
// class added to arrows when at the extremes (i.e. prev/first arrows are "disabled" when on the first page)
|
|
|
|
cssDisabled: 'disabled', // Note there is no period "." in front of this class name
|
|
|
|
|
|
|
|
// stuff not set by the user
|
|
|
|
totalRows: 0,
|
|
|
|
totalPages: 0,
|
|
|
|
filteredRows: 0,
|
|
|
|
filteredPages: 0,
|
|
|
|
ajaxCounter: 0,
|
|
|
|
currentFilters: [],
|
|
|
|
startRow: 0,
|
|
|
|
endRow: 0,
|
|
|
|
$size: null,
|
|
|
|
last: {}
|
2012-11-28 02:55:36 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
};
|
2012-11-28 02:55:36 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
var pagerEvents = 'filterInit filterStart filterEnd sortEnd disablePager enablePager destroyPager updateComplete ' +
|
2015-03-25 20:22:07 +00:00
|
|
|
'pageSize pageSet pageAndSize pagerUpdate refreshComplete ',
|
2015-01-21 00:48:11 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
$this = this,
|
|
|
|
|
|
|
|
// hide arrows at extremes
|
|
|
|
pagerArrows = function( table, p, disable ) {
|
|
|
|
var a = 'addClass',
|
|
|
|
r = 'removeClass',
|
|
|
|
d = p.cssDisabled,
|
|
|
|
dis = !!disable,
|
|
|
|
first = ( dis || p.page === 0 ),
|
|
|
|
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);
|
|
|
|
p.$container.find(p.cssNext + ',' + p.cssLast)[ last ? a : r ](d).attr('aria-disabled', last);
|
|
|
|
}
|
|
|
|
},
|
2012-11-28 02:55:36 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
calcFilters = function(table, p) {
|
|
|
|
var normalized, indx, len,
|
2015-02-26 00:43:59 +00:00
|
|
|
c = table.config,
|
2014-10-09 21:49:49 +00:00
|
|
|
hasFilters = c.$table.hasClass('hasFilters');
|
2016-06-08 12:52:57 +00:00
|
|
|
if (hasFilters && !p.ajaxUrl) {
|
|
|
|
if (ts.isEmptyObject(c.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;
|
|
|
|
} else {
|
|
|
|
p.filteredRows = 0;
|
|
|
|
normalized = c.cache[0].normalized;
|
|
|
|
len = normalized.length;
|
|
|
|
for (indx = 0; indx < len; indx++) {
|
|
|
|
p.filteredRows += p.regexRows.test(normalized[indx][c.columns].$row[0].className) ? 0 : 1;
|
|
|
|
}
|
2015-02-26 00:43:59 +00:00
|
|
|
}
|
2016-06-08 12:52:57 +00:00
|
|
|
} else if (!hasFilters) {
|
|
|
|
p.filteredRows = p.totalRows;
|
2014-07-11 19:51:50 +00:00
|
|
|
}
|
2016-06-08 12:52:57 +00:00
|
|
|
},
|
2014-10-09 21:49:49 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
updatePageDisplay = function(table, p, completed) {
|
|
|
|
if ( p.initializing ) { return; }
|
|
|
|
var s, t, $out, indx, len, options,
|
2014-10-09 21:49:49 +00:00
|
|
|
c = table.config,
|
2015-07-15 02:22:52 +00:00
|
|
|
namespace = c.namespace + 'pager',
|
2015-10-30 21:13:36 +00:00
|
|
|
sz = parsePageSize( p, p.size, 'get' ); // don't allow dividing by zero
|
2016-06-08 12:52:57 +00:00
|
|
|
if (sz === 'all') { sz = p.totalRows; }
|
|
|
|
if (p.countChildRows) { t[ t.length ] = c.cssChildRow; }
|
|
|
|
p.totalPages = Math.ceil( p.totalRows / sz ); // needed for "pageSize" method
|
|
|
|
c.totalRows = p.totalRows;
|
|
|
|
parsePageNumber( table, p );
|
|
|
|
calcFilters(table, p);
|
|
|
|
c.filteredRows = p.filteredRows;
|
|
|
|
p.filteredPages = Math.ceil( p.filteredRows / sz ) || 0;
|
|
|
|
if ( getTotalPages( table, p ) >= 0 ) {
|
|
|
|
t = (sz * p.page > p.filteredRows) && completed;
|
|
|
|
p.page = (t) ? p.pageReset || 0 : p.page;
|
|
|
|
p.startRow = (t) ? sz * p.page + 1 : (p.filteredRows === 0 ? 0 : sz * p.page + 1);
|
|
|
|
p.endRow = Math.min( p.filteredRows, p.totalRows, sz * ( p.page + 1 ) );
|
|
|
|
$out = p.$container.find(p.cssPageDisplay);
|
|
|
|
// 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 )
|
2013-10-10 02:41:58 +00:00
|
|
|
// {page} = one-based index; {page+#} = zero based index +/- value
|
2015-07-23 04:29:51 +00:00
|
|
|
.replace(/\{page([\-+]\d+)?\}/gi, function(m, n){
|
2013-12-15 11:57:49 +00:00
|
|
|
return p.totalPages ? p.page + (n ? parseInt(n, 10) : 1) : 0;
|
2013-10-10 02:41:58 +00:00
|
|
|
})
|
|
|
|
// {totalPages}, {extra}, {extra:0} (array) or {extra : key} (object)
|
|
|
|
.replace(/\{\w+(\s*:\s*\w+)?\}/gi, function(m){
|
2014-07-22 12:42:15 +00:00
|
|
|
var len, indx,
|
2016-06-08 12:52:57 +00:00
|
|
|
str = m.replace(/[{}\s]/g, ''),
|
|
|
|
extra = str.split(':'),
|
|
|
|
data = p.ajaxData,
|
|
|
|
// return zero for default page/row numbers
|
|
|
|
deflt = /(rows?|pages?)$/i.test(str) ? 0 : '';
|
2014-07-22 12:42:15 +00:00
|
|
|
if (/(startRow|page)/.test(extra[0]) && extra[1] === 'input') {
|
|
|
|
len = ('' + (extra[0] === 'page' ? p.totalPages : p.totalRows)).length;
|
|
|
|
indx = extra[0] === 'page' ? p.page + 1 : p.startRow;
|
|
|
|
return '<input type="text" class="ts-' + extra[0] + '" style="max-width:' + len + 'em" value="' + indx + '"/>';
|
|
|
|
}
|
2013-12-02 16:11:36 +00:00
|
|
|
return extra.length > 1 && data && data[extra[0]] ? data[extra[0]][extra[1]] : p[str] || (data ? data[str] : deflt) || deflt;
|
2013-10-10 02:41:58 +00:00
|
|
|
});
|
2016-06-08 12:52:57 +00:00
|
|
|
if ( p.$goto.length ) {
|
|
|
|
t = '';
|
|
|
|
options = buildPageSelect( table, p );
|
|
|
|
len = options.length;
|
|
|
|
for (indx = 0; indx < len; indx++) {
|
|
|
|
t += '<option value="' + options[indx] + '">' + options[indx] + '</option>';
|
|
|
|
}
|
|
|
|
// innerHTML doesn't work in IE9 - http://support2.microsoft.com/kb/276228
|
|
|
|
p.$goto.html(t).val( p.page + 1 );
|
2015-02-26 00:43:59 +00:00
|
|
|
}
|
2016-06-08 12:52:57 +00:00
|
|
|
if ($out.length) {
|
|
|
|
$out[ ($out[0].nodeName === 'INPUT') ? 'val' : 'html' ](s);
|
|
|
|
// rebind startRow/page inputs
|
|
|
|
$out.find('.ts-startRow, .ts-page').unbind('change' + namespace).bind('change' + namespace, function(){
|
|
|
|
var v = $(this).val(),
|
2016-05-01 20:25:01 +00:00
|
|
|
pg = $(this).hasClass('ts-startRow') ? Math.floor( v / sz ) + 1 : v;
|
2016-06-08 12:52:57 +00:00
|
|
|
c.$table.triggerHandler('pageSet' + namespace, [ pg ]);
|
|
|
|
});
|
|
|
|
}
|
2015-02-27 23:37:14 +00:00
|
|
|
}
|
2016-06-08 12:52:57 +00:00
|
|
|
pagerArrows( table, p );
|
|
|
|
fixHeight(table, p);
|
|
|
|
if (p.initialized && completed !== false) {
|
|
|
|
if (c.debug) {
|
|
|
|
console.log('Pager: Triggering pagerComplete');
|
|
|
|
}
|
|
|
|
c.$table.triggerHandler('pagerComplete', p);
|
|
|
|
// save pager info to storage
|
|
|
|
if (p.savePages && ts.storage) {
|
|
|
|
ts.storage(table, p.storageKey, {
|
|
|
|
page : p.page,
|
|
|
|
size : sz === p.totalRows ? 'all' : sz
|
|
|
|
});
|
|
|
|
}
|
2013-10-03 12:27:23 +00:00
|
|
|
}
|
2016-06-08 12:52:57 +00:00
|
|
|
},
|
2012-11-28 02:55:36 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
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,
|
2015-11-19 15:41:35 +00:00
|
|
|
pg = getTotalPages( table, p ) || 1,
|
2014-09-17 06:45:27 +00:00
|
|
|
// make skip set size multiples of 5
|
|
|
|
skip_set_size = Math.ceil( ( pg / p.maxOptionSize ) / 5 ) * 5,
|
|
|
|
large_collection = pg > p.maxOptionSize,
|
|
|
|
current_page = p.page + 1,
|
|
|
|
start_page = skip_set_size,
|
|
|
|
end_page = pg - skip_set_size,
|
2015-07-23 04:29:51 +00:00
|
|
|
option_pages = [ 1 ],
|
2014-09-17 06:45:27 +00:00
|
|
|
// construct default options pages array
|
|
|
|
option_pages_start_page = (large_collection) ? skip_set_size : 1;
|
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
for ( i = option_pages_start_page; i <= pg; ) {
|
|
|
|
option_pages[ option_pages.length ] = i;
|
|
|
|
i = i + ( large_collection ? skip_set_size : 1 );
|
2014-09-17 06:45:27 +00:00
|
|
|
}
|
2016-06-08 12:52:57 +00:00
|
|
|
option_pages[ option_pages.length ] = pg;
|
|
|
|
if (large_collection) {
|
|
|
|
focus_option_pages = [];
|
|
|
|
// don't allow central focus size to be > 5 on either side of current page
|
|
|
|
central_focus_size = Math.max( Math.floor( p.maxOptionSize / skip_set_size ) - 1, 5 );
|
|
|
|
|
|
|
|
start_page = current_page - central_focus_size;
|
|
|
|
if (start_page < 1) { start_page = 1; }
|
|
|
|
end_page = current_page + central_focus_size;
|
|
|
|
if (end_page > pg) { end_page = pg; }
|
|
|
|
// construct an array to get a focus set around the current page
|
|
|
|
for (i = start_page; i <= end_page ; i++) {
|
|
|
|
focus_option_pages[ focus_option_pages.length ] = i;
|
|
|
|
}
|
2014-09-17 06:45:27 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
// keep unique values
|
|
|
|
option_pages = $.grep(option_pages, function(value, indx) {
|
|
|
|
return $.inArray(value, option_pages) === indx;
|
|
|
|
});
|
2014-09-17 06:45:27 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
option_length = option_pages.length;
|
|
|
|
focus_length = focus_option_pages.length;
|
2014-09-17 06:45:27 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
// make sure at all option_pages aren't replaced
|
|
|
|
if (option_length - focus_length > skip_set_size / 2 && option_length + focus_length > p.maxOptionSize ) {
|
|
|
|
insert_index = Math.floor(option_length / 2) - Math.floor(focus_length / 2);
|
|
|
|
Array.prototype.splice.apply(option_pages, [ insert_index, focus_length ]);
|
|
|
|
}
|
|
|
|
option_pages = option_pages.concat(focus_option_pages);
|
2014-09-17 06:45:27 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
}
|
2014-09-17 06:45:27 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
// keep unique values again
|
|
|
|
option_pages = $.grep(option_pages, function(value, indx) {
|
|
|
|
return $.inArray(value, option_pages) === indx;
|
|
|
|
})
|
|
|
|
.sort(function(a, b) { return a - b; });
|
2014-09-17 06:45:27 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
return option_pages;
|
|
|
|
},
|
2014-09-17 06:45:27 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
fixHeight = function(table, p) {
|
|
|
|
var d, h,
|
2013-09-30 14:23:14 +00:00
|
|
|
c = table.config,
|
|
|
|
$b = c.$tbodies.eq(0);
|
2016-06-08 12:52:57 +00:00
|
|
|
$b.find('tr.pagerSavedHeightSpacer').remove();
|
|
|
|
if (p.fixedHeight && !p.isDisabled) {
|
|
|
|
h = $.data(table, 'pagerSavedHeight');
|
|
|
|
if (h) {
|
|
|
|
d = h - $b.height();
|
|
|
|
if ( d > 5 && $.data(table, 'pagerLastSize') === p.size &&
|
2016-05-01 20:25:01 +00:00
|
|
|
$b.children('tr:visible').length < (p.size === 'all' ? p.totalRows : p.size) ) {
|
2016-06-08 12:52:57 +00:00
|
|
|
$b.append('<tr class="pagerSavedHeightSpacer ' + c.selectorRemove.slice(1) + '" style="height:' + d + 'px;"></tr>');
|
|
|
|
}
|
2012-11-28 02:55:36 +00:00
|
|
|
}
|
|
|
|
}
|
2016-06-08 12:52:57 +00:00
|
|
|
},
|
2012-11-28 02:55:36 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
changeHeight = function(table, p) {
|
|
|
|
var h,
|
2014-10-09 23:22:10 +00:00
|
|
|
c = table.config,
|
|
|
|
$b = c.$tbodies.eq(0);
|
2016-06-08 12:52:57 +00:00
|
|
|
$b.find('tr.pagerSavedHeightSpacer').remove();
|
|
|
|
if (!$b.children('tr:visible').length) {
|
|
|
|
$b.append('<tr class="pagerSavedHeightSpacer ' + c.selectorRemove.slice(1) + '"><td> </td></tr>');
|
|
|
|
}
|
|
|
|
h = $b.children('tr').eq(0).height() * (p.size === 'all' ? p.totalRows : p.size);
|
|
|
|
$.data(table, 'pagerSavedHeight', h);
|
|
|
|
fixHeight(table, p);
|
|
|
|
$.data(table, 'pagerLastSize', p.size);
|
|
|
|
},
|
|
|
|
|
|
|
|
hideRows = function(table, p){
|
|
|
|
if (!p.ajaxUrl) {
|
|
|
|
var i,
|
|
|
|
lastIndex = 0,
|
|
|
|
c = table.config,
|
|
|
|
rows = c.$tbodies.eq(0).children('tr'),
|
|
|
|
l = rows.length,
|
|
|
|
sz = p.size === 'all' ? p.totalRows : p.size,
|
|
|
|
s = ( p.page * sz ),
|
|
|
|
e = s + sz,
|
|
|
|
last = 0, // for cache indexing
|
|
|
|
j = 0; // size counter
|
|
|
|
p.cacheIndex = [];
|
|
|
|
for ( i = 0; i < l; i++ ){
|
2016-06-28 09:28:35 +00:00
|
|
|
if ( !p.regexFiltered.test(rows[i].className) ) {
|
2016-06-08 12:52:57 +00:00
|
|
|
if (j === s && rows[i].className.match(c.cssChildRow)) {
|
|
|
|
// hide child rows @ start of pager (if already visible)
|
|
|
|
rows[i].style.display = 'none';
|
|
|
|
} else {
|
|
|
|
rows[i].style.display = ( j >= s && j < e ) ? '' : 'none';
|
|
|
|
if (last !== j && j >= s && j < e) {
|
|
|
|
p.cacheIndex[ p.cacheIndex.length ] = i;
|
|
|
|
last = j;
|
|
|
|
}
|
|
|
|
// don't count child rows
|
|
|
|
j += rows[i].className.match(c.cssChildRow + '|' + c.selectorRemove.slice(1)) && !p.countChildRows ? 0 : 1;
|
|
|
|
if ( j === e && rows[i].style.display !== 'none' && rows[i].className.match(ts.css.cssHasChild) ) {
|
|
|
|
lastIndex = i;
|
|
|
|
}
|
2014-03-31 10:07:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-06-08 12:52:57 +00:00
|
|
|
// add any attached child rows to last row of pager. Fixes part of issue #396
|
|
|
|
if ( lastIndex > 0 && rows[lastIndex].className.match(ts.css.cssHasChild) ) {
|
|
|
|
while ( ++lastIndex < l && rows[lastIndex].className.match(c.cssChildRow) ) {
|
|
|
|
rows[lastIndex].style.display = '';
|
|
|
|
}
|
2012-11-28 02:55:36 +00:00
|
|
|
}
|
|
|
|
}
|
2016-06-08 12:52:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
hideRowsSetup = function(table, p){
|
|
|
|
p.size = parsePageSize( p, p.$size.val(), 'get' );
|
|
|
|
p.$size.val( p.size );
|
|
|
|
$.data(table, 'pagerLastSize', p.size);
|
|
|
|
pagerArrows( table, p );
|
|
|
|
if ( !p.removeRows ) {
|
2013-09-30 14:23:14 +00:00
|
|
|
hideRows(table, p);
|
2016-06-08 12:52:57 +00:00
|
|
|
$(table).bind('sortEnd filterEnd '.split(' ').join(table.config.namespace + 'pager '), function(){
|
|
|
|
hideRows(table, p);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2012-11-28 02:55:36 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
renderAjax = function(data, table, p, xhr, settings, exception){
|
|
|
|
// process data
|
|
|
|
if ( typeof p.ajaxProcessing === 'function' ) {
|
2015-11-09 17:42:42 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
// in case nothing is returned by ajax, empty out the table; see #1032
|
|
|
|
// but do it before calling pager_ajaxProcessing because that function may add content
|
|
|
|
// directly to the table
|
|
|
|
table.config.$tbodies.eq(0).empty();
|
2015-11-09 17:42:42 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
// ajaxProcessing result: [ total, rows, headers ]
|
|
|
|
var i, j, t, hsh, $f, $sh, $headers, $h, icon, th, d, l, rr_count, len, sz,
|
2013-09-30 14:23:14 +00:00
|
|
|
c = table.config,
|
2015-05-17 16:10:49 +00:00
|
|
|
$table = c.$table,
|
2013-09-30 14:23:14 +00:00
|
|
|
tds = '',
|
2014-05-26 13:19:52 +00:00
|
|
|
result = p.ajaxProcessing(data, table, xhr) || [ 0, [] ],
|
2015-05-17 16:10:49 +00:00
|
|
|
hl = $table.find('thead th').length;
|
2013-03-28 01:01:39 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
// Clean up any previous error.
|
|
|
|
ts.showError( table );
|
2013-05-07 15:13:50 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
if ( exception ) {
|
|
|
|
if (c.debug) {
|
|
|
|
console.error('Pager: >> Ajax Error', xhr, settings, exception);
|
|
|
|
}
|
|
|
|
ts.showError( table, xhr, settings, exception );
|
|
|
|
c.$tbodies.eq(0).children('tr').detach();
|
|
|
|
p.totalRows = 0;
|
2013-10-10 02:41:58 +00:00
|
|
|
} else {
|
2016-06-08 12:52:57 +00:00
|
|
|
// process ajax object
|
|
|
|
if (!$.isArray(result)) {
|
|
|
|
p.ajaxData = result;
|
|
|
|
c.totalRows = p.totalRows = result.total;
|
|
|
|
c.filteredRows = p.filteredRows = typeof result.filteredRows !== 'undefined' ? result.filteredRows : result.total;
|
|
|
|
th = result.headers;
|
|
|
|
d = result.rows || [];
|
|
|
|
} else {
|
|
|
|
// allow [ total, rows, headers ] or [ rows, total, headers ]
|
|
|
|
t = isNaN(result[0]) && !isNaN(result[1]);
|
|
|
|
// ensure a zero returned row count doesn't fail the logical ||
|
|
|
|
rr_count = result[t ? 1 : 0];
|
|
|
|
p.totalRows = isNaN(rr_count) ? p.totalRows || 0 : rr_count;
|
|
|
|
// can't set filtered rows when returning an array
|
|
|
|
c.totalRows = c.filteredRows = p.filteredRows = p.totalRows;
|
|
|
|
// set row data to empty array if nothing found - see http://stackoverflow.com/q/30875583/145346
|
|
|
|
d = p.totalRows === 0 ? [] : result[t ? 0 : 1] || []; // row data
|
|
|
|
th = result[2]; // headers
|
2014-04-09 12:24:17 +00:00
|
|
|
}
|
2016-06-08 12:52:57 +00:00
|
|
|
l = d && d.length;
|
|
|
|
if (d instanceof jQuery) {
|
|
|
|
if (p.processAjaxOnInit) {
|
|
|
|
// append jQuery object
|
|
|
|
c.$tbodies.eq(0).empty();
|
|
|
|
c.$tbodies.eq(0).append(d);
|
2013-05-07 15:13:50 +00:00
|
|
|
}
|
2016-06-08 12:52:57 +00:00
|
|
|
} else if (l) {
|
|
|
|
// build table from array
|
|
|
|
for ( i = 0; i < l; i++ ) {
|
|
|
|
tds += '<tr>';
|
|
|
|
for ( j = 0; j < d[i].length; j++ ) {
|
|
|
|
// build tbody cells; watch for data containing HTML markup - see #434
|
|
|
|
tds += /^\s*<td/.test(d[i][j]) ? $.trim(d[i][j]) : '<td>' + d[i][j] + '</td>';
|
2013-05-07 15:13:50 +00:00
|
|
|
}
|
2016-06-08 12:52:57 +00:00
|
|
|
tds += '</tr>';
|
|
|
|
}
|
|
|
|
// add rows to first tbody
|
|
|
|
if (p.processAjaxOnInit) {
|
|
|
|
c.$tbodies.eq(0).html( tds );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p.processAjaxOnInit = true;
|
|
|
|
// only add new header text if the length matches
|
|
|
|
if ( th && th.length === hl ) {
|
|
|
|
hsh = $table.hasClass('hasStickyHeaders');
|
|
|
|
$sh = hsh ? c.widgetOptions.$sticky.children('thead:first').children('tr').children() : '';
|
|
|
|
$f = $table.find('tfoot tr:first').children();
|
|
|
|
// don't change td headers (may contain pager)
|
|
|
|
$headers = c.$headers.filter( 'th ' );
|
|
|
|
len = $headers.length;
|
|
|
|
for ( j = 0; j < len; j++ ) {
|
|
|
|
$h = $headers.eq( j );
|
|
|
|
// add new test within the first span it finds, or just in the header
|
|
|
|
if ( $h.find('.' + ts.css.icon).length ) {
|
|
|
|
icon = $h.find('.' + ts.css.icon).clone(true);
|
|
|
|
$h.find('.tablesorter-header-inner').html( th[j] ).append(icon);
|
|
|
|
if ( hsh && $sh.length ) {
|
|
|
|
icon = $sh.eq(j).find('.' + ts.css.icon).clone(true);
|
|
|
|
$sh.eq(j).find('.tablesorter-header-inner').html( th[j] ).append(icon);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$h.find('.tablesorter-header-inner').html( th[j] );
|
|
|
|
if (hsh && $sh.length) {
|
|
|
|
$sh.eq(j).find('.tablesorter-header-inner').html( th[j] );
|
|
|
|
}
|
2013-05-07 15:13:50 +00:00
|
|
|
}
|
2016-06-08 12:52:57 +00:00
|
|
|
$f.eq(j).html( th[j] );
|
2013-05-07 15:13:50 +00:00
|
|
|
}
|
2015-05-17 16:10:49 +00:00
|
|
|
}
|
2013-05-07 15:13:50 +00:00
|
|
|
}
|
2016-06-08 12:52:57 +00:00
|
|
|
if (c.showProcessing) {
|
|
|
|
ts.isProcessing(table); // remove loading icon
|
2013-12-13 00:46:45 +00:00
|
|
|
}
|
2016-06-08 12:52:57 +00:00
|
|
|
sz = parsePageSize( p, p.size, 'get' );
|
|
|
|
// make sure last pager settings are saved, prevents multiple server side calls with
|
|
|
|
// the same parameters
|
|
|
|
p.totalPages = sz === 'all' ? 1 : Math.ceil( p.totalRows / sz );
|
|
|
|
p.last.totalRows = p.totalRows;
|
|
|
|
p.last.currentFilters = p.currentFilters;
|
|
|
|
p.last.sortList = (c.sortList || []).join(',');
|
|
|
|
updatePageDisplay(table, p, false);
|
|
|
|
// tablesorter core updateCache (not pager)
|
|
|
|
ts.updateCache( c, function(){
|
|
|
|
if (p.initialized) {
|
|
|
|
// apply widgets after table has rendered & after a delay to prevent
|
|
|
|
// multiple applyWidget blocking code from blocking this trigger
|
|
|
|
setTimeout(function(){
|
|
|
|
if (c.debug) {
|
|
|
|
console.log('Pager: Triggering pagerChange');
|
|
|
|
}
|
|
|
|
$table.triggerHandler( 'pagerChange', p );
|
|
|
|
ts.applyWidget( table );
|
|
|
|
updatePageDisplay(table, p, true);
|
|
|
|
}, 0);
|
|
|
|
}
|
|
|
|
});
|
2014-03-07 03:13:45 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
}
|
|
|
|
if (!p.initialized) {
|
|
|
|
pagerInitialized(table, p);
|
|
|
|
}
|
|
|
|
},
|
2012-11-28 02:55:36 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
getAjax = function(table, p) {
|
|
|
|
var url = getAjaxUrl(table, p),
|
2015-07-15 02:22:52 +00:00
|
|
|
$doc = $(document),
|
|
|
|
counter,
|
|
|
|
c = table.config,
|
|
|
|
namespace = c.namespace + 'pager';
|
2016-06-08 12:52:57 +00:00
|
|
|
if ( url !== '' ) {
|
|
|
|
if (c.showProcessing) {
|
|
|
|
ts.isProcessing(table, true); // show loading icon
|
|
|
|
}
|
|
|
|
$doc.bind('ajaxError' + namespace, function(e, xhr, settings, exception) {
|
|
|
|
renderAjax(null, table, p, xhr, settings, exception);
|
|
|
|
$doc.unbind('ajaxError' + namespace);
|
|
|
|
});
|
2013-11-27 09:43:38 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
counter = ++p.ajaxCounter;
|
2013-11-27 09:43:38 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
p.last.ajaxUrl = url; // remember processed url
|
|
|
|
p.ajaxObject.url = url; // from the ajaxUrl option and modified by customAjaxUrl
|
|
|
|
p.ajaxObject.success = function(data, status, jqxhr) {
|
|
|
|
// Refuse to process old ajax commands that were overwritten by new ones - see #443
|
|
|
|
if (counter < p.ajaxCounter){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
renderAjax(data, table, p, jqxhr);
|
|
|
|
$doc.unbind('ajaxError' + namespace);
|
|
|
|
if (typeof p.oldAjaxSuccess === 'function') {
|
|
|
|
p.oldAjaxSuccess(data);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
if (c.debug) {
|
|
|
|
console.log('Pager: Ajax initialized', p.ajaxObject);
|
2014-04-18 16:04:45 +00:00
|
|
|
}
|
2016-06-08 12:52:57 +00:00
|
|
|
$.ajax(p.ajaxObject);
|
2013-11-09 05:49:30 +00:00
|
|
|
}
|
2016-06-08 12:52:57 +00:00
|
|
|
},
|
2013-03-28 01:01:39 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
getAjaxUrl = function(table, p) {
|
|
|
|
var indx, len,
|
2015-02-26 00:43:59 +00:00
|
|
|
c = table.config,
|
2013-11-09 05:49:30 +00:00
|
|
|
url = (p.ajaxUrl) ? p.ajaxUrl
|
2013-04-04 21:32:03 +00:00
|
|
|
// allow using "{page+1}" in the url string to switch to a non-zero based index
|
2015-07-23 04:29:51 +00:00
|
|
|
.replace(/\{page([\-+]\d+)?\}/, function(s, n){ return p.page + (n ? parseInt(n, 10) : 0); })
|
2016-05-01 20:25:01 +00:00
|
|
|
// this will pass "all" to server when size is set to "all"
|
2013-09-30 14:23:14 +00:00
|
|
|
.replace(/\{size\}/g, p.size) : '',
|
2016-06-08 12:52:57 +00:00
|
|
|
sortList = c.sortList,
|
|
|
|
filterList = p.currentFilters || $(table).data('lastSearch') || [],
|
|
|
|
sortCol = url.match(/\{\s*sort(?:List)?\s*:\s*(\w*)\s*\}/),
|
|
|
|
filterCol = url.match(/\{\s*filter(?:List)?\s*:\s*(\w*)\s*\}/),
|
2013-04-12 18:02:08 +00:00
|
|
|
arry = [];
|
2016-06-08 12:52:57 +00:00
|
|
|
if (sortCol) {
|
|
|
|
sortCol = sortCol[1];
|
|
|
|
len = sortList.length;
|
|
|
|
for (indx = 0; indx < len; indx++) {
|
|
|
|
arry[ arry.length ] = sortCol + '[' + sortList[indx][0] + ']=' + sortList[indx][1];
|
2012-12-17 17:33:46 +00:00
|
|
|
}
|
2016-06-08 12:52:57 +00:00
|
|
|
// if the arry is empty, just add the col parameter... "&{sortList:col}" becomes "&col"
|
|
|
|
url = url.replace(/\{\s*sort(?:List)?\s*:\s*(\w*)\s*\}/g, arry.length ? arry.join('&') : sortCol );
|
|
|
|
arry = [];
|
2015-02-26 00:43:59 +00:00
|
|
|
}
|
2016-06-08 12:52:57 +00:00
|
|
|
if (filterCol) {
|
|
|
|
filterCol = filterCol[1];
|
|
|
|
len = filterList.length;
|
|
|
|
for (indx = 0; indx < len; indx++) {
|
|
|
|
if (filterList[indx]) {
|
|
|
|
arry[ arry.length ] = filterCol + '[' + indx + ']=' + encodeURIComponent( filterList[indx] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// if the arry is empty, just add the fcol parameter... "&{filterList:fcol}" becomes "&fcol"
|
|
|
|
url = url.replace(/\{\s*filter(?:List)?\s*:\s*(\w*)\s*\}/g, arry.length ? arry.join('&') : filterCol );
|
|
|
|
p.currentFilters = filterList;
|
|
|
|
}
|
|
|
|
if ( typeof p.customAjaxUrl === 'function' ) {
|
|
|
|
url = p.customAjaxUrl(table, url);
|
|
|
|
}
|
|
|
|
if (c.debug) {
|
|
|
|
console.log('Pager: Ajax url = ' + url);
|
|
|
|
}
|
|
|
|
return url;
|
|
|
|
},
|
2012-11-28 02:55:36 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
renderTable = function(table, rows, p) {
|
|
|
|
var $tb, index, count, added,
|
2014-03-07 02:28:47 +00:00
|
|
|
$t = $(table),
|
|
|
|
c = table.config,
|
2014-04-18 16:36:19 +00:00
|
|
|
f = c.$table.hasClass('hasFilters'),
|
2013-10-18 03:59:07 +00:00
|
|
|
l = rows && rows.length || 0, // rows may be undefined
|
2016-05-01 20:25:01 +00:00
|
|
|
e = p.size === 'all' ? p.totalRows : p.size,
|
|
|
|
s = ( p.page * e );
|
2016-06-08 12:52:57 +00:00
|
|
|
if ( l < 1 ) {
|
|
|
|
if (c.debug) {
|
|
|
|
console.warn('Pager: >> No rows for pager to render');
|
|
|
|
}
|
|
|
|
// empty table, abort!
|
|
|
|
return;
|
2014-07-11 19:51:50 +00:00
|
|
|
}
|
2016-06-08 12:52:57 +00:00
|
|
|
if ( p.page >= p.totalPages ) {
|
|
|
|
// lets not render the table more than once
|
|
|
|
moveToLastPage(table, p);
|
2015-02-27 23:37:14 +00:00
|
|
|
}
|
2016-06-08 12:52:57 +00:00
|
|
|
p.cacheIndex = [];
|
|
|
|
p.isDisabled = false; // needed because sorting will change the page and re-enable the pager
|
|
|
|
if (p.initialized) {
|
|
|
|
if (c.debug) {
|
|
|
|
console.log('Pager: Triggering pagerChange');
|
|
|
|
}
|
|
|
|
$t.triggerHandler( 'pagerChange', p );
|
|
|
|
}
|
|
|
|
if ( !p.removeRows ) {
|
|
|
|
hideRows(table, p);
|
|
|
|
} else {
|
|
|
|
ts.clearTableBody(table);
|
|
|
|
$tb = ts.processTbody(table, c.$tbodies.eq(0), true);
|
|
|
|
// not filtered, start from the calculated starting point (s)
|
|
|
|
// if filtered, start from zero
|
|
|
|
index = f ? 0 : s;
|
|
|
|
count = f ? 0 : s;
|
|
|
|
added = 0;
|
|
|
|
while (added < e && index < rows.length) {
|
2016-06-28 09:28:35 +00:00
|
|
|
if (!f || !p.regexFiltered.test(rows[index][0].className)){
|
2016-06-08 12:52:57 +00:00
|
|
|
count++;
|
|
|
|
if (count > s && added <= e) {
|
|
|
|
added++;
|
|
|
|
p.cacheIndex[ p.cacheIndex.length ] = index;
|
|
|
|
$tb.append(rows[index]);
|
|
|
|
}
|
2014-04-18 16:36:19 +00:00
|
|
|
}
|
2016-06-08 12:52:57 +00:00
|
|
|
index++;
|
2014-04-18 16:36:19 +00:00
|
|
|
}
|
2016-06-08 12:52:57 +00:00
|
|
|
ts.processTbody(table, $tb, false);
|
2012-11-28 02:55:36 +00:00
|
|
|
}
|
2016-06-08 12:52:57 +00:00
|
|
|
updatePageDisplay(table, p);
|
|
|
|
if (table.isUpdating) {
|
|
|
|
if (c.debug) {
|
|
|
|
console.log('Pager: Triggering updateComplete');
|
|
|
|
}
|
|
|
|
$t.triggerHandler('updateComplete', [ table, true ]);
|
2015-02-27 23:37:14 +00:00
|
|
|
}
|
2016-06-08 12:52:57 +00:00
|
|
|
},
|
2012-11-28 02:55:36 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
showAllRows = function(table, p) {
|
|
|
|
var index, $controls, len;
|
|
|
|
if ( p.ajax ) {
|
|
|
|
pagerArrows( table, p, true );
|
|
|
|
} else {
|
|
|
|
$.data(table, 'pagerLastPage', p.page);
|
|
|
|
$.data(table, 'pagerLastSize', p.size);
|
|
|
|
p.page = 0;
|
|
|
|
p.size = 'all';
|
|
|
|
p.totalPages = 1;
|
|
|
|
$(table)
|
2014-01-11 19:08:37 +00:00
|
|
|
.addClass('pagerDisabled')
|
|
|
|
.removeAttr('aria-describedby')
|
|
|
|
.find('tr.pagerSavedHeightSpacer').remove();
|
2016-06-08 12:52:57 +00:00
|
|
|
renderTable(table, table.config.rowsCopy, p);
|
|
|
|
p.isDisabled = true;
|
|
|
|
ts.applyWidget( table );
|
|
|
|
if (table.config.debug) {
|
|
|
|
console.log('Pager: Disabled');
|
|
|
|
}
|
2013-11-09 05:49:30 +00:00
|
|
|
}
|
2016-06-08 12:52:57 +00:00
|
|
|
// disable size selector
|
|
|
|
$controls = p.$size
|
2015-05-17 16:10:49 +00:00
|
|
|
.add( p.$goto )
|
|
|
|
.add( p.$container.find( '.ts-startRow, .ts-page' ) );
|
2016-06-08 12:52:57 +00:00
|
|
|
len = $controls.length;
|
|
|
|
for ( index = 0; index < len; index++ ) {
|
|
|
|
$controls.eq( index )
|
2015-05-17 16:10:49 +00:00
|
|
|
.attr( 'aria-disabled', 'true' )
|
|
|
|
.addClass( p.cssDisabled )[0].disabled = true;
|
2016-06-08 12:52:57 +00:00
|
|
|
}
|
|
|
|
},
|
2012-11-28 02:55:36 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
// updateCache if delayInit: true
|
|
|
|
updateCache = function(table) {
|
|
|
|
var c = table.config,
|
2014-07-11 19:51:50 +00:00
|
|
|
p = c.pager;
|
2016-06-08 12:52:57 +00:00
|
|
|
// tablesorter core updateCache (not pager)
|
|
|
|
ts.updateCache( c, function(){
|
|
|
|
var i,
|
2014-07-11 19:51:50 +00:00
|
|
|
rows = [],
|
2015-02-14 21:00:04 +00:00
|
|
|
n = table.config.cache[0].normalized;
|
2016-06-08 12:52:57 +00:00
|
|
|
p.totalRows = n.length;
|
|
|
|
for (i = 0; i < p.totalRows; i++) {
|
|
|
|
rows[ rows.length ] = n[i][c.columns].$row;
|
|
|
|
}
|
|
|
|
c.rowsCopy = rows;
|
|
|
|
moveToPage(table, p, true);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
moveToPage = function(table, p, pageMoved) {
|
|
|
|
if ( p.isDisabled ) { return; }
|
|
|
|
var tmp,
|
2016-01-24 16:10:58 +00:00
|
|
|
c = table.config,
|
2014-03-07 02:28:47 +00:00
|
|
|
$t = $(table),
|
2014-10-09 21:49:49 +00:00
|
|
|
l = p.last;
|
2016-06-08 12:52:57 +00:00
|
|
|
if ( pageMoved !== false && p.initialized && ts.isEmptyObject(c.cache)) {
|
|
|
|
return updateCache(table);
|
|
|
|
}
|
|
|
|
// 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 ['','',''],
|
|
|
|
// making the next if comparison think the filters are different (joined by commas). Fixes #202.
|
|
|
|
l.currentFilters = (l.currentFilters || []).join('') === '' ? [] : l.currentFilters;
|
|
|
|
p.currentFilters = (p.currentFilters || []).join('') === '' ? [] : p.currentFilters;
|
|
|
|
// don't allow rendering multiple times on the same page/size/totalRows/filters/sorts
|
|
|
|
if ( l.page === p.page && l.size === p.size && l.totalRows === p.totalRows &&
|
2013-11-09 05:49:30 +00:00
|
|
|
(l.currentFilters || []).join(',') === (p.currentFilters || []).join(',') &&
|
2014-10-02 16:30:39 +00:00
|
|
|
// check for ajax url changes see #730
|
2014-09-28 13:37:47 +00:00
|
|
|
(l.ajaxUrl || '') === (p.ajaxObject.url || '') &&
|
2014-10-02 16:30:39 +00:00
|
|
|
// & ajax url option changes (dynamically add/remove/rename sort & filter parameters)
|
|
|
|
(l.optAjaxUrl || '') === (p.ajaxUrl || '') &&
|
2013-11-09 05:49:30 +00:00
|
|
|
l.sortList === (c.sortList || []).join(',') ) { return; }
|
2016-06-08 12:52:57 +00:00
|
|
|
if (c.debug) {
|
|
|
|
console.log('Pager: Changing to page ' + p.page);
|
|
|
|
}
|
|
|
|
p.last = {
|
|
|
|
page : p.page,
|
|
|
|
size : p.size,
|
|
|
|
// fixes #408; modify sortList otherwise it auto-updates
|
|
|
|
sortList : (c.sortList || []).join(','),
|
|
|
|
totalRows : p.totalRows,
|
|
|
|
currentFilters : p.currentFilters || [],
|
|
|
|
ajaxUrl : p.ajaxObject.url || '',
|
|
|
|
optAjaxUrl : p.ajaxUrl || ''
|
|
|
|
};
|
|
|
|
if (p.ajax) {
|
|
|
|
if ( !p.processAjaxOnInit && !ts.isEmptyObject(p.initialRows) ) {
|
|
|
|
p.processAjaxOnInit = true;
|
|
|
|
tmp = p.initialRows;
|
|
|
|
p.totalRows = typeof tmp.total !== 'undefined' ? tmp.total :
|
2016-01-24 16:10:58 +00:00
|
|
|
( c.debug ? console.error('Pager: no initial total page set!') || 0 : 0 );
|
2016-06-08 12:52:57 +00:00
|
|
|
p.filteredRows = typeof tmp.filtered !== 'undefined' ? tmp.filtered :
|
2016-01-24 16:10:58 +00:00
|
|
|
( c.debug ? console.error('Pager: no initial filtered page set!') || 0 : 0 );
|
2016-06-08 12:52:57 +00:00
|
|
|
pagerInitialized( table, p );
|
|
|
|
} else {
|
|
|
|
getAjax(table, p);
|
|
|
|
}
|
|
|
|
} else if (!p.ajax) {
|
|
|
|
renderTable(table, c.rowsCopy, p);
|
2015-02-27 23:37:14 +00:00
|
|
|
}
|
2016-06-08 12:52:57 +00:00
|
|
|
$.data(table, 'pagerLastPage', p.page);
|
|
|
|
if (p.initialized && pageMoved !== false) {
|
2015-02-27 23:37:14 +00:00
|
|
|
if (c.debug) {
|
2016-06-08 12:52:57 +00:00
|
|
|
console.log('Pager: Triggering pageMoved');
|
|
|
|
}
|
|
|
|
$t.triggerHandler('pageMoved', p);
|
|
|
|
ts.applyWidget( table );
|
|
|
|
if (table.isUpdating) {
|
|
|
|
if (c.debug) {
|
|
|
|
console.log('Pager: Triggering updateComplete');
|
|
|
|
}
|
|
|
|
$t.triggerHandler('updateComplete', [ table, true ]);
|
2015-02-27 23:37:14 +00:00
|
|
|
}
|
2014-03-07 02:28:47 +00:00
|
|
|
}
|
2016-06-08 12:52:57 +00:00
|
|
|
},
|
2012-11-28 02:55:36 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
getTotalPages = function( table, p ) {
|
|
|
|
return ts.hasWidget( table, 'filter' ) ? Math.min( p.totalPages, p.filteredPages ) : p.totalPages;
|
|
|
|
},
|
2015-11-19 15:41:35 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
// set to either set or get value
|
|
|
|
parsePageSize = function( p, size, mode ) {
|
|
|
|
var s = parseInt( size, 10 ) || p.size || p.settings.size || 10;
|
2016-07-09 23:55:59 +00:00
|
|
|
return p.initialized && (/all/i.test( size ) || s === p.totalRows) ?
|
2015-11-19 15:41:35 +00:00
|
|
|
// "get" to get `p.size` or "set" to set `p.$size.val()`
|
2016-05-01 20:25:01 +00:00
|
|
|
'all' : ( mode === 'get' ? s : p.size );
|
2016-06-08 12:52:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
parsePageNumber = function( table, p ) {
|
|
|
|
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 && min >= 0 ) { p.page = min; }
|
|
|
|
return p.page;
|
|
|
|
},
|
|
|
|
|
|
|
|
setPageSize = function(table, size, p) {
|
|
|
|
p.size = parsePageSize( p, size, 'get' );
|
|
|
|
p.$size.val( parsePageSize( p, p.size, 'set' ) );
|
|
|
|
$.data(table, 'pagerLastPage', parsePageNumber( table, p ) );
|
|
|
|
$.data(table, 'pagerLastSize', p.size);
|
|
|
|
p.totalPages = p.size === 'all' ? 1 : Math.ceil( p.totalRows / p.size );
|
|
|
|
p.filteredPages = p.size === 'all' ? 1 : Math.ceil( p.filteredRows / p.size );
|
|
|
|
moveToPage(table, p);
|
|
|
|
},
|
2012-11-28 02:55:36 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
moveToFirstPage = function(table, p) {
|
2013-09-30 14:23:14 +00:00
|
|
|
p.page = 0;
|
2016-06-08 12:52:57 +00:00
|
|
|
moveToPage(table, p);
|
|
|
|
},
|
|
|
|
|
|
|
|
moveToLastPage = function(table, p) {
|
|
|
|
p.page = getTotalPages( table, p ) - 1;
|
|
|
|
moveToPage(table, p);
|
|
|
|
},
|
2016-01-24 16:10:58 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
moveToNextPage = function(table, p) {
|
|
|
|
p.page++;
|
|
|
|
var last = getTotalPages( table, p ) - 1;
|
|
|
|
if ( p.page >= last ) {
|
|
|
|
p.page = last;
|
|
|
|
}
|
|
|
|
moveToPage(table, p);
|
|
|
|
},
|
|
|
|
|
|
|
|
moveToPrevPage = function(table, p) {
|
|
|
|
p.page--;
|
|
|
|
if ( p.page <= 0 ) {
|
|
|
|
p.page = 0;
|
|
|
|
}
|
|
|
|
moveToPage(table, p);
|
|
|
|
},
|
|
|
|
|
|
|
|
pagerInitialized = function(table, p) {
|
|
|
|
p.initialized = true;
|
|
|
|
p.initializing = false;
|
|
|
|
if (table.config.debug) {
|
|
|
|
console.log('Pager: Triggering pagerInitialized');
|
|
|
|
}
|
|
|
|
$(table).triggerHandler( 'pagerInitialized', p );
|
|
|
|
ts.applyWidget( table );
|
|
|
|
updatePageDisplay(table, p);
|
|
|
|
},
|
|
|
|
|
|
|
|
destroyPager = function(table, p) {
|
|
|
|
var c = table.config,
|
2015-07-30 22:37:59 +00:00
|
|
|
namespace = c.namespace + 'pager',
|
|
|
|
ctrls = [ p.cssFirst, p.cssPrev, p.cssNext, p.cssLast, p.cssGoto, p.cssPageSize ].join( ',' );
|
2016-06-08 12:52:57 +00:00
|
|
|
showAllRows(table, p);
|
|
|
|
p.$container
|
2015-07-30 22:37:59 +00:00
|
|
|
// hide pager controls
|
|
|
|
.hide()
|
|
|
|
// unbind
|
|
|
|
.find( ctrls )
|
|
|
|
.unbind( namespace );
|
2016-06-08 12:52:57 +00:00
|
|
|
c.appender = null; // remove pager appender function
|
|
|
|
c.$table.unbind( namespace );
|
|
|
|
if (ts.storage) {
|
|
|
|
ts.storage(table, p.storageKey, '');
|
|
|
|
}
|
|
|
|
delete c.pager;
|
|
|
|
delete c.rowsCopy;
|
|
|
|
},
|
2012-11-28 02:55:36 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
enablePager = function(table, p, triggered) {
|
|
|
|
var info, size,
|
2014-01-07 01:10:07 +00:00
|
|
|
c = table.config;
|
2016-06-08 12:52:57 +00:00
|
|
|
p.$size.add(p.$goto).add(p.$container.find('.ts-startRow, .ts-page'))
|
2014-07-22 12:42:15 +00:00
|
|
|
.removeClass(p.cssDisabled)
|
|
|
|
.removeAttr('disabled')
|
|
|
|
.attr('aria-disabled', 'false');
|
2016-06-08 12:52:57 +00:00
|
|
|
p.isDisabled = false;
|
|
|
|
p.page = $.data(table, 'pagerLastPage') || p.page || 0;
|
|
|
|
size = p.$size.find('option[selected]').val();
|
|
|
|
p.size = $.data(table, 'pagerLastSize') || parsePageSize( p, size, 'get' );
|
|
|
|
p.$size.val( p.size ); // set page size
|
|
|
|
p.totalPages = p.size === 'all' ? 1 : 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';
|
|
|
|
p.$container.find(p.cssPageDisplay).attr('id', info);
|
|
|
|
c.$table.attr('aria-describedby', info);
|
2013-11-09 05:49:30 +00:00
|
|
|
}
|
2016-06-08 12:52:57 +00:00
|
|
|
changeHeight(table, p);
|
|
|
|
if ( triggered ) {
|
|
|
|
// tablesorter core update table
|
|
|
|
ts.update( c );
|
|
|
|
setPageSize(table, p.size, p);
|
|
|
|
hideRowsSetup(table, p);
|
|
|
|
if (c.debug) {
|
|
|
|
console.log('Pager: Enabled');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2012-11-28 02:55:36 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
$this.appender = function(table, rows) {
|
|
|
|
var c = table.config,
|
2013-11-01 18:43:18 +00:00
|
|
|
p = c.pager;
|
2016-06-08 12:52:57 +00:00
|
|
|
if ( !p.ajax ) {
|
|
|
|
c.rowsCopy = rows;
|
|
|
|
p.totalRows = p.countChildRows ? c.$tbodies.eq(0).children('tr').length : rows.length;
|
|
|
|
p.size = $.data(table, 'pagerLastSize') || p.size || p.settings.size || 10;
|
|
|
|
p.totalPages = p.size === 'all' ? 1 : Math.ceil( p.totalRows / p.size );
|
|
|
|
renderTable(table, rows, p);
|
|
|
|
// update display here in case all rows are removed
|
|
|
|
updatePageDisplay(table, p, false);
|
|
|
|
}
|
|
|
|
};
|
2012-11-28 02:55:36 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
$this.construct = function(settings) {
|
|
|
|
return this.each(function() {
|
|
|
|
// check if tablesorter has initialized
|
|
|
|
if (!(this.config && this.hasInitialized)) { return; }
|
|
|
|
var t, ctrls, fxn, size,
|
2013-09-30 14:23:14 +00:00
|
|
|
table = this,
|
|
|
|
c = table.config,
|
2014-04-23 21:09:26 +00:00
|
|
|
wo = c.widgetOptions,
|
2014-04-18 16:04:45 +00:00
|
|
|
p = c.pager = $.extend( true, {}, $.tablesorterPager.defaults, settings ),
|
2013-09-30 14:23:14 +00:00
|
|
|
$t = c.$table,
|
2015-07-15 02:22:52 +00:00
|
|
|
namespace = c.namespace + 'pager',
|
2013-09-30 14:23:14 +00:00
|
|
|
// added in case the pager is reinitialized after being destroyed.
|
|
|
|
pager = p.$container = $(p.container).addClass('tablesorter-pager').show();
|
2016-06-08 12:52:57 +00:00
|
|
|
// save a copy of the original settings
|
|
|
|
p.settings = $.extend( true, {}, $.tablesorterPager.defaults, settings );
|
|
|
|
if (c.debug) {
|
|
|
|
console.log('Pager: Initializing');
|
|
|
|
}
|
|
|
|
p.oldAjaxSuccess = p.oldAjaxSuccess || p.ajaxObject.success;
|
|
|
|
c.appender = $this.appender;
|
|
|
|
p.initializing = true;
|
|
|
|
if (p.savePages && ts.storage) {
|
|
|
|
t = ts.storage(table, p.storageKey) || {}; // fixes #387
|
|
|
|
p.page = isNaN(t.page) ? p.page : t.page;
|
|
|
|
p.size = t.size === 'all' ? t.size : ( isNaN( t.size ) ? p.size : t.size ) || p.setSize || 10;
|
|
|
|
$.data(table, 'pagerLastSize', p.size);
|
|
|
|
pager.find(p.cssPageSize).val(p.size);
|
|
|
|
}
|
|
|
|
// skipped rows
|
|
|
|
p.regexRows = new RegExp('(' + (wo.filter_filteredRow || 'filtered') + '|' + c.selectorRemove.slice(1) + '|' + c.cssChildRow + ')');
|
2016-06-28 09:28:35 +00:00
|
|
|
p.regexFiltered = new RegExp(wo.filter_filteredRow || 'filtered');
|
2014-04-23 21:09:26 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
$t
|
2015-07-30 22:37:59 +00:00
|
|
|
// .unbind( namespace ) adding in jQuery 1.4.3 ( I think )
|
2015-07-15 02:22:52 +00:00
|
|
|
.unbind( pagerEvents.split(' ').join(namespace + ' ').replace(/\s+/g, ' ') )
|
|
|
|
.bind('filterInit filterStart '.split(' ').join(namespace + ' '), function(e, filters) {
|
2014-12-25 16:04:44 +00:00
|
|
|
p.currentFilters = $.isArray(filters) ? filters : c.$table.data('lastSearch');
|
2014-11-03 14:05:22 +00:00
|
|
|
// don't change page if filters are the same (pager updating, etc)
|
2014-11-03 18:57:33 +00:00
|
|
|
if (e.type === 'filterStart' && p.pageReset !== false && (c.lastCombinedFilter || '') !== (p.currentFilters || []).join('')) {
|
2014-04-20 06:59:23 +00:00
|
|
|
p.page = p.pageReset; // fixes #456 & #565
|
|
|
|
}
|
2012-12-19 16:35:46 +00:00
|
|
|
})
|
|
|
|
// update pager after filter widget completes
|
2015-07-15 02:22:52 +00:00
|
|
|
.bind('filterEnd sortEnd '.split(' ').join(namespace + ' '), function() {
|
2014-11-03 14:05:22 +00:00
|
|
|
p.currentFilters = c.$table.data('lastSearch');
|
2014-10-31 16:52:25 +00:00
|
|
|
if (p.initialized || p.initializing) {
|
2014-07-11 19:51:50 +00:00
|
|
|
if (c.delayInit && c.rowsCopy && c.rowsCopy.length === 0) {
|
|
|
|
// make sure we have a copy of all table rows once the cache has been built
|
|
|
|
updateCache(table);
|
|
|
|
}
|
2014-12-23 02:44:29 +00:00
|
|
|
updatePageDisplay(table, p, false);
|
2014-04-23 20:47:54 +00:00
|
|
|
moveToPage(table, p, false);
|
2015-10-22 21:41:34 +00:00
|
|
|
ts.applyWidget( table );
|
2013-06-13 12:14:43 +00:00
|
|
|
}
|
2012-12-19 16:35:46 +00:00
|
|
|
})
|
2015-07-30 18:32:54 +00:00
|
|
|
.bind('disablePager' + namespace, function(e){
|
2013-03-23 14:41:33 +00:00
|
|
|
e.stopPropagation();
|
2013-09-30 14:23:14 +00:00
|
|
|
showAllRows(table, p);
|
2012-12-19 16:35:46 +00:00
|
|
|
})
|
2015-07-30 18:32:54 +00:00
|
|
|
.bind('enablePager' + namespace, function(e){
|
2013-03-23 14:41:33 +00:00
|
|
|
e.stopPropagation();
|
2013-09-30 14:23:14 +00:00
|
|
|
enablePager(table, p, true);
|
2012-12-19 16:35:46 +00:00
|
|
|
})
|
2015-07-30 18:32:54 +00:00
|
|
|
.bind('destroyPager' + namespace, function(e){
|
2013-03-23 14:41:33 +00:00
|
|
|
e.stopPropagation();
|
2013-09-30 14:23:14 +00:00
|
|
|
destroyPager(table, p);
|
2012-12-19 16:35:46 +00:00
|
|
|
})
|
2015-07-15 02:22:52 +00:00
|
|
|
.bind('updateComplete' + namespace, function(e, table, triggered){
|
2013-03-23 14:41:33 +00:00
|
|
|
e.stopPropagation();
|
2014-08-12 15:32:52 +00:00
|
|
|
// table can be unintentionally undefined in tablesorter v2.17.7 and earlier
|
2015-03-12 00:20:51 +00:00
|
|
|
// don't recalculate total rows/pages if using ajax
|
|
|
|
if ( !table || triggered || p.ajax ) { return; }
|
2014-08-12 15:32:52 +00:00
|
|
|
var $rows = c.$tbodies.eq(0).children('tr').not(c.selectorRemove);
|
2014-05-22 04:39:55 +00:00
|
|
|
p.totalRows = $rows.length - ( p.countChildRows ? 0 : $rows.filter('.' + c.cssChildRow).length );
|
2016-05-01 20:25:01 +00:00
|
|
|
p.totalPages = p.size === 'all' ? 1 : Math.ceil( p.totalRows / p.size );
|
2014-08-12 15:32:52 +00:00
|
|
|
if ($rows.length && c.rowsCopy && c.rowsCopy.length === 0) {
|
|
|
|
// make a copy of all table rows once the cache has been built
|
|
|
|
updateCache(table);
|
|
|
|
}
|
2014-10-09 23:22:10 +00:00
|
|
|
if ( p.page >= p.totalPages ) {
|
|
|
|
moveToLastPage(table, p);
|
|
|
|
}
|
2013-09-30 14:23:14 +00:00
|
|
|
hideRows(table, p);
|
2014-10-09 23:22:10 +00:00
|
|
|
changeHeight(table, p);
|
|
|
|
updatePageDisplay(table, p, true);
|
2013-01-22 16:34:30 +00:00
|
|
|
})
|
2015-10-26 01:55:48 +00:00
|
|
|
.bind('pageSize refreshComplete '.split(' ').join(namespace + ' '), function(e, size){
|
2013-03-23 14:41:33 +00:00
|
|
|
e.stopPropagation();
|
2015-10-30 21:13:36 +00:00
|
|
|
setPageSize(table, parsePageSize( p, size, 'get' ), p);
|
2013-09-30 14:23:14 +00:00
|
|
|
hideRows(table, p);
|
|
|
|
updatePageDisplay(table, p, false);
|
2013-02-10 17:47:59 +00:00
|
|
|
})
|
2015-10-26 01:55:48 +00:00
|
|
|
.bind('pageSet pagerUpdate '.split(' ').join(namespace + ' '), function(e, num){
|
2013-03-23 14:41:33 +00:00
|
|
|
e.stopPropagation();
|
2015-01-21 00:48:11 +00:00
|
|
|
// force pager refresh
|
2015-03-25 16:16:55 +00:00
|
|
|
if (e.type === 'pagerUpdate') {
|
2015-10-26 01:55:48 +00:00
|
|
|
num = typeof num === 'undefined' ? p.page + 1 : num;
|
2015-03-25 16:16:55 +00:00
|
|
|
p.last.page = true;
|
|
|
|
}
|
2015-10-26 01:55:48 +00:00
|
|
|
p.page = (parseInt(num, 10) || 1) - 1;
|
2014-07-11 19:51:50 +00:00
|
|
|
moveToPage(table, p, true);
|
2013-09-30 14:23:14 +00:00
|
|
|
updatePageDisplay(table, p, false);
|
2015-01-16 17:21:23 +00:00
|
|
|
})
|
2015-07-15 02:22:52 +00:00
|
|
|
.bind('pageAndSize' + namespace, function(e, page, size){
|
2015-01-16 17:21:23 +00:00
|
|
|
e.stopPropagation();
|
|
|
|
p.page = (parseInt(page, 10) || 1) - 1;
|
2015-10-30 21:13:36 +00:00
|
|
|
setPageSize(table, parsePageSize( p, size, 'get' ), p);
|
2015-01-16 17:21:23 +00:00
|
|
|
moveToPage(table, p, true);
|
|
|
|
hideRows(table, p);
|
|
|
|
updatePageDisplay(table, p, false);
|
2012-11-28 02:55:36 +00:00
|
|
|
});
|
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
// clicked controls
|
|
|
|
ctrls = [ p.cssFirst, p.cssPrev, p.cssNext, p.cssLast ];
|
|
|
|
fxn = [ moveToFirstPage, moveToPrevPage, moveToNextPage, moveToLastPage ];
|
|
|
|
if (c.debug && !pager.length) {
|
|
|
|
console.warn('Pager: >> Container not found');
|
|
|
|
}
|
|
|
|
pager.find(ctrls.join(','))
|
2015-07-23 04:29:51 +00:00
|
|
|
.attr('tabindex', 0)
|
2015-07-15 02:22:52 +00:00
|
|
|
.unbind('click' + namespace)
|
|
|
|
.bind('click' + namespace, function(e){
|
2013-11-09 05:49:30 +00:00
|
|
|
e.stopPropagation();
|
2013-05-06 14:09:22 +00:00
|
|
|
var i, $t = $(this), l = ctrls.length;
|
2013-09-30 14:23:14 +00:00
|
|
|
if ( !$t.hasClass(p.cssDisabled) ) {
|
2012-12-19 16:35:46 +00:00
|
|
|
for (i = 0; i < l; i++) {
|
2013-05-06 14:09:22 +00:00
|
|
|
if ($t.is(ctrls[i])) {
|
2013-09-30 14:23:14 +00:00
|
|
|
fxn[i](table, p);
|
2012-12-19 16:35:46 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 02:55:36 +00:00
|
|
|
});
|
2012-12-19 16:35:46 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
// goto selector
|
|
|
|
p.$goto = pager.find(p.cssGoto);
|
|
|
|
if ( p.$goto.length ) {
|
|
|
|
p.$goto
|
2015-07-15 02:22:52 +00:00
|
|
|
.unbind('change' + namespace)
|
|
|
|
.bind('change' + namespace, function(){
|
2013-09-30 14:23:14 +00:00
|
|
|
p.page = $(this).val() - 1;
|
2014-07-11 19:51:50 +00:00
|
|
|
moveToPage(table, p, true);
|
2013-10-18 18:38:46 +00:00
|
|
|
updatePageDisplay(table, p, false);
|
2012-12-19 16:35:46 +00:00
|
|
|
});
|
2016-06-08 12:52:57 +00:00
|
|
|
} else if (c.debug) {
|
|
|
|
console.warn('Pager: >> Goto selector not found');
|
|
|
|
}
|
|
|
|
// page size selector
|
|
|
|
p.$size = pager.find(p.cssPageSize);
|
|
|
|
if ( p.$size.length ) {
|
|
|
|
// setting an option as selected appears to cause issues with initial page size
|
|
|
|
p.$size.find('option').removeAttr('selected');
|
|
|
|
p.$size.unbind('change' + namespace).bind('change' + namespace, function() {
|
|
|
|
if ( !$(this).hasClass(p.cssDisabled) ) {
|
|
|
|
var size = $(this).val();
|
|
|
|
p.$size.val( size ); // in case there are more than one pagers
|
|
|
|
setPageSize(table, size, p);
|
|
|
|
changeHeight(table, p);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
} else if (c.debug) {
|
|
|
|
console.warn('Pager: >> Size selector not found');
|
|
|
|
}
|
2012-11-28 02:55:36 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
// clear initialized flag
|
|
|
|
p.initialized = false;
|
|
|
|
// before initialization event
|
|
|
|
$t.triggerHandler('pagerBeforeInitialized', p);
|
|
|
|
|
|
|
|
enablePager(table, p, false);
|
|
|
|
if ( typeof p.ajaxUrl === 'string' ) {
|
|
|
|
// ajax pager; interact with database
|
|
|
|
p.ajax = true;
|
|
|
|
// When filtering with ajax, allow only custom filtering function, disable default
|
|
|
|
// filtering since it will be done server side.
|
|
|
|
c.widgetOptions.filter_serversideFiltering = true;
|
|
|
|
c.serverSideSorting = true;
|
|
|
|
moveToPage(table, p);
|
|
|
|
} else {
|
|
|
|
p.ajax = false;
|
|
|
|
// Regular pager; all rows stored in memory
|
|
|
|
ts.appendCache( c, true ); // true = don't apply widgets
|
|
|
|
hideRowsSetup(table, p);
|
2015-02-27 23:37:14 +00:00
|
|
|
}
|
2016-06-08 12:52:57 +00:00
|
|
|
|
|
|
|
// pager initialized
|
|
|
|
if (!p.ajax && !p.initialized) {
|
|
|
|
p.initializing = false;
|
|
|
|
p.initialized = true;
|
|
|
|
moveToPage(table, p);
|
|
|
|
if (c.debug) {
|
|
|
|
console.log('Pager: Triggering pagerInitialized');
|
|
|
|
}
|
|
|
|
c.$table.triggerHandler( 'pagerInitialized', p );
|
|
|
|
if ( !( c.widgetOptions.filter_initialized && ts.hasWidget(table, 'filter') ) ) {
|
|
|
|
updatePageDisplay(table, p, false);
|
|
|
|
}
|
2014-10-31 20:18:30 +00:00
|
|
|
}
|
2015-06-02 15:47:29 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
// make the hasWidget function think that the pager widget is being used
|
|
|
|
c.widgetInit.pager = true;
|
|
|
|
});
|
|
|
|
};
|
2012-11-28 02:55:36 +00:00
|
|
|
|
2016-06-08 12:52:57 +00:00
|
|
|
}()
|
|
|
|
});
|
2014-02-05 12:10:55 +00:00
|
|
|
|
|
|
|
// see #486
|
2015-08-19 21:33:32 +00:00
|
|
|
ts.showError = function( table, xhr, settings, exception ) {
|
2015-08-15 15:56:42 +00:00
|
|
|
var $row,
|
2016-06-20 17:18:41 +00:00
|
|
|
$table = $( table ),
|
|
|
|
c = $table[0].config,
|
|
|
|
wo = c && c.widgetOptions,
|
|
|
|
errorRow = c.pager && c.pager.cssErrorRow ||
|
|
|
|
wo && wo.pager_css && wo.pager_css.errorRow ||
|
|
|
|
'tablesorter-errorRow',
|
|
|
|
typ = typeof xhr,
|
|
|
|
valid = true,
|
|
|
|
message = '',
|
|
|
|
removeRow = function(){
|
|
|
|
c.$table.find( 'thead' ).find( '.' + errorRow ).remove();
|
|
|
|
};
|
2015-08-15 15:56:42 +00:00
|
|
|
|
|
|
|
if ( !$table.length ) {
|
|
|
|
console.error('tablesorter showError: no table parameter passed');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-19 21:33:32 +00:00
|
|
|
// ajaxError callback for plugin or widget - see #992
|
|
|
|
if ( typeof c.pager.ajaxError === 'function' ) {
|
|
|
|
valid = c.pager.ajaxError( c, xhr, settings, exception );
|
|
|
|
if ( valid === false ) {
|
|
|
|
return removeRow();
|
2015-08-15 15:56:42 +00:00
|
|
|
} else {
|
2015-08-19 21:33:32 +00:00
|
|
|
message = valid;
|
|
|
|
}
|
|
|
|
} else if ( typeof wo.pager_ajaxError === 'function' ) {
|
|
|
|
valid = wo.pager_ajaxError( c, xhr, settings, exception );
|
|
|
|
if ( valid === false ) {
|
|
|
|
return removeRow();
|
|
|
|
} else {
|
|
|
|
message = valid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( message === '' ) {
|
|
|
|
if ( typ === 'object' ) {
|
2015-08-15 15:56:42 +00:00
|
|
|
message =
|
2016-06-20 17:18:41 +00:00
|
|
|
xhr.status === 0 ? 'Not connected, verify Network' :
|
|
|
|
xhr.status === 404 ? 'Requested page not found [404]' :
|
|
|
|
xhr.status === 500 ? 'Internal Server Error [500]' :
|
|
|
|
exception === 'parsererror' ? 'Requested JSON parse failed' :
|
|
|
|
exception === 'timeout' ? 'Time out error' :
|
|
|
|
exception === 'abort' ? 'Ajax Request aborted' :
|
|
|
|
'Uncaught error: ' + xhr.statusText + ' [' + xhr.status + ']';
|
2015-08-19 21:33:32 +00:00
|
|
|
} else if ( typ === 'string' ) {
|
|
|
|
// keep backward compatibility (external usage just passes a message string)
|
|
|
|
message = xhr;
|
|
|
|
} else {
|
|
|
|
// remove all error rows
|
|
|
|
return removeRow();
|
2014-02-05 12:10:55 +00:00
|
|
|
}
|
2015-05-17 16:10:49 +00:00
|
|
|
}
|
2015-08-15 15:56:42 +00:00
|
|
|
|
2015-08-19 21:33:32 +00:00
|
|
|
// allow message to include entire row HTML!
|
2015-08-15 15:56:42 +00:00
|
|
|
$row = ( /tr\>/.test(message) ? $(message) : $('<tr><td colspan="' + c.columns + '">' + message + '</td></tr>') )
|
2016-06-20 17:18:41 +00:00
|
|
|
.click( function() {
|
|
|
|
$( this ).remove();
|
|
|
|
})
|
|
|
|
// add error row to thead instead of tbody, or clicking on the header will result in a parser error
|
|
|
|
.appendTo( c.$table.find( 'thead:first' ) )
|
|
|
|
.addClass( errorRow + ' ' + c.selectorRemove.slice(1) )
|
|
|
|
.attr({
|
|
|
|
role : 'alert',
|
|
|
|
'aria-live' : 'assertive'
|
|
|
|
});
|
2015-08-15 15:56:42 +00:00
|
|
|
|
2014-02-05 12:10:55 +00:00
|
|
|
};
|
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
// extend plugin scope
|
|
|
|
$.fn.extend({
|
|
|
|
tablesorterPager: $.tablesorterPager.construct
|
|
|
|
});
|
2012-11-28 02:55:36 +00:00
|
|
|
|
2013-09-30 14:19:18 +00:00
|
|
|
})(jQuery);
|