2017-04-02 11:33:20 +00:00
|
|
|
/*! Widget: Pager - updated 4/2/2017 (v2.28.6) */
|
2015-03-26 15:48:43 +00:00
|
|
|
/* Requires tablesorter v2.8+ and jQuery 1.7+
|
|
|
|
* by Rob Garrison
|
|
|
|
*/
|
2013-10-18 03:59:07 +00:00
|
|
|
/*jshint browser:true, jquery:true, unused:false */
|
|
|
|
;(function($){
|
2015-07-23 04:29:51 +00:00
|
|
|
'use strict';
|
|
|
|
var tsp,
|
2013-10-18 03:59:07 +00:00
|
|
|
ts = $.tablesorter;
|
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
ts.addWidget({
|
|
|
|
id: 'pager',
|
|
|
|
priority: 55, // load pager after filter widget
|
2015-11-20 15:27:22 +00:00
|
|
|
options: {
|
2015-07-23 04:29:51 +00:00
|
|
|
// output default: '{page}/{totalPages}'
|
2015-11-20 15:27:22 +00:00
|
|
|
// possible variables: {size}, {page}, {totalPages}, {filteredPages}, {startRow},
|
|
|
|
// {endRow}, {filteredRows} and {totalRows}
|
2015-07-23 04:29:51 +00:00
|
|
|
pager_output: '{startRow} to {endRow} of {totalRows} rows', // '{page}/{totalPages}'
|
|
|
|
|
|
|
|
// apply disabled classname to the pager arrows when the rows at either extreme is visible
|
|
|
|
pager_updateArrows: true,
|
|
|
|
|
|
|
|
// starting page of the pager (zero based index)
|
|
|
|
pager_startPage: 0,
|
|
|
|
|
|
|
|
// reset pager after filtering; set to desired page #
|
|
|
|
// set to false to not change page at filter start
|
|
|
|
pager_pageReset: 0,
|
|
|
|
|
|
|
|
// Number of visible rows
|
|
|
|
pager_size: 10,
|
|
|
|
|
|
|
|
// Number of options to include in the pager number selector
|
|
|
|
pager_maxOptionSize: 20,
|
|
|
|
|
2015-11-20 15:27:22 +00:00
|
|
|
// Save pager page & size if the storage script is loaded (requires $.tablesorter.storage
|
|
|
|
// in jquery.tablesorter.widgets.js)
|
2015-07-23 04:29:51 +00:00
|
|
|
pager_savePages: true,
|
|
|
|
|
|
|
|
// defines custom storage key
|
|
|
|
pager_storageKey: 'tablesorter-pager',
|
|
|
|
|
2015-11-20 15:27:22 +00:00
|
|
|
// 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
|
2015-07-23 04:29:51 +00:00
|
|
|
pager_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.
|
|
|
|
pager_countChildRows: false,
|
|
|
|
|
|
|
|
// remove rows from the table to speed up the sort of large tables.
|
2015-11-20 15:27:22 +00:00
|
|
|
// setting this to false, only hides the non-visible rows; needed if you plan to add/remove rows with
|
|
|
|
// the pager enabled.
|
2015-07-23 04:29:51 +00:00
|
|
|
pager_removeRows: false, // removing rows in larger tables speeds up the sort
|
|
|
|
|
|
|
|
// 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
|
|
|
|
pager_ajaxUrl: null,
|
|
|
|
|
|
|
|
// modify the url after all processing has been applied
|
2015-11-20 15:27:22 +00:00
|
|
|
pager_customAjaxUrl: function( table, url ) { return url; },
|
2015-07-23 04:29:51 +00:00
|
|
|
|
2015-08-15 15:56:42 +00:00
|
|
|
// ajax error callback from $.tablesorter.showError function
|
2015-08-19 21:33:32 +00:00
|
|
|
// pager_ajaxError: function( config, xhr, settings, exception ){ return exception; };
|
2015-08-15 15:56:42 +00:00
|
|
|
// returning false will abort the error message
|
|
|
|
pager_ajaxError: null,
|
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
// modify the $.ajax object to allow complete control over your ajax requests
|
|
|
|
pager_ajaxObject: {
|
|
|
|
dataType: 'json'
|
|
|
|
},
|
|
|
|
|
|
|
|
// set this to false if you want to block ajax loading on init
|
|
|
|
pager_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
|
|
|
|
// ]
|
2015-11-20 15:27:22 +00:00
|
|
|
pager_ajaxProcessing: function( ajax ){ return [ 0, [], null ]; },
|
2015-07-23 04:29:51 +00:00
|
|
|
|
|
|
|
// css class names of pager arrows
|
|
|
|
pager_css: {
|
|
|
|
container : 'tablesorter-pager',
|
2015-11-20 15:27:22 +00:00
|
|
|
// error information row (don't include period at beginning)
|
|
|
|
errorRow : 'tablesorter-errorRow',
|
|
|
|
// class added to arrows @ extremes (i.e. prev/first arrows 'disabled' on first page)
|
|
|
|
disabled : 'disabled'
|
2015-07-23 04:29:51 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// jQuery selectors
|
|
|
|
pager_selectors: {
|
|
|
|
container : '.pager', // target the pager markup
|
|
|
|
first : '.first', // go to first page arrow
|
|
|
|
prev : '.prev', // previous page arrow
|
|
|
|
next : '.next', // next page arrow
|
|
|
|
last : '.last', // go to last page arrow
|
2016-12-16 23:13:02 +00:00
|
|
|
// goto is a reserved word #657
|
2015-07-23 04:29:51 +00:00
|
|
|
gotoPage : '.gotoPage', // go to page selector - select dropdown that sets the current page
|
|
|
|
pageDisplay : '.pagedisplay', // location of where the 'output' is displayed
|
|
|
|
pageSize : '.pagesize' // page size selector - select dropdown that sets the 'size' option
|
|
|
|
}
|
|
|
|
},
|
2015-11-20 15:27:22 +00:00
|
|
|
init: function( table ) {
|
|
|
|
tsp.init( table );
|
2015-07-23 04:29:51 +00:00
|
|
|
},
|
|
|
|
// only update to complete sorter initialization
|
2015-11-20 15:27:22 +00:00
|
|
|
format: function( table, c ) {
|
|
|
|
if ( !( c.pager && c.pager.initialized ) ) {
|
|
|
|
return tsp.initComplete( c );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
2015-11-20 15:27:22 +00:00
|
|
|
tsp.moveToPage( c, c.pager, false );
|
2015-07-23 04:29:51 +00:00
|
|
|
},
|
2015-11-20 15:27:22 +00:00
|
|
|
remove: function( table, c, wo, refreshing ) {
|
|
|
|
tsp.destroyPager( c, refreshing );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
|
|
|
});
|
2014-09-17 06:45:27 +00:00
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
/* pager widget functions */
|
|
|
|
tsp = ts.pager = {
|
2013-10-18 03:59:07 +00:00
|
|
|
|
2015-11-20 15:27:22 +00:00
|
|
|
init: function( table ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
// check if tablesorter has initialized
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( table.hasInitialized && table.config.pager && table.config.pager.initialized ) { return; }
|
2015-07-23 04:29:51 +00:00
|
|
|
var t,
|
|
|
|
c = table.config,
|
|
|
|
wo = c.widgetOptions,
|
|
|
|
s = wo.pager_selectors,
|
|
|
|
|
|
|
|
// save pager variables
|
|
|
|
p = c.pager = $.extend({
|
|
|
|
totalPages: 0,
|
|
|
|
filteredRows: 0,
|
|
|
|
filteredPages: 0,
|
|
|
|
currentFilters: [],
|
|
|
|
page: wo.pager_startPage,
|
|
|
|
startRow: 0,
|
|
|
|
endRow: 0,
|
|
|
|
ajaxCounter: 0,
|
|
|
|
$size: null,
|
|
|
|
last: {},
|
|
|
|
// save original pager size
|
|
|
|
setSize: wo.pager_size,
|
2015-07-30 22:37:59 +00:00
|
|
|
setPage: wo.pager_startPage
|
2015-11-20 15:27:22 +00:00
|
|
|
}, c.pager );
|
2015-07-23 04:29:51 +00:00
|
|
|
|
|
|
|
// pager initializes multiple times before table has completed initialization
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( p.isInitializing ) { return; }
|
2015-07-23 04:29:51 +00:00
|
|
|
|
|
|
|
p.isInitializing = true;
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( c.debug ) {
|
|
|
|
console.log( 'Pager: Initializing' );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
2014-01-16 23:16:56 +00:00
|
|
|
|
2015-11-20 15:27:22 +00:00
|
|
|
p.size = $.data( table, 'pagerLastSize' ) || wo.pager_size;
|
2015-07-23 04:29:51 +00:00
|
|
|
// added in case the pager is reinitialized after being destroyed.
|
2015-11-20 15:27:22 +00:00
|
|
|
p.$container = $( s.container ).addClass( wo.pager_css.container ).show();
|
|
|
|
p.totalRows = c.$tbodies.eq( 0 )
|
|
|
|
.children( 'tr' )
|
|
|
|
.not( wo.pager_countChildRows ? '' : '.' + c.cssChildRow )
|
|
|
|
.length;
|
2015-07-23 04:29:51 +00:00
|
|
|
p.oldAjaxSuccess = p.oldAjaxSuccess || wo.pager_ajaxObject.success;
|
|
|
|
c.appender = tsp.appender;
|
|
|
|
p.initializing = true;
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( wo.pager_savePages && ts.storage ) {
|
|
|
|
t = ts.storage( table, wo.pager_storageKey ) || {}; // fixes #387
|
|
|
|
p.page = ( isNaN( t.page ) ? p.page : t.page ) || p.setPage || 0;
|
2016-05-01 20:25:01 +00:00
|
|
|
p.size = t.size === 'all' ? t.size : ( isNaN( t.size ) ? p.size : t.size ) || p.setSize || 10;
|
2017-04-02 08:40:10 +00:00
|
|
|
tsp.setPageSize( c, p.size );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
2013-10-18 03:59:07 +00:00
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
// skipped rows
|
2015-11-20 15:27:22 +00:00
|
|
|
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' );
|
2013-10-30 21:56:08 +00:00
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
// clear initialized flag
|
|
|
|
p.initialized = false;
|
|
|
|
// before initialization event
|
2015-12-02 01:38:56 +00:00
|
|
|
c.$table.triggerHandler( 'pagerBeforeInitialized', c );
|
2013-10-18 03:59:07 +00:00
|
|
|
|
2015-11-20 15:27:22 +00:00
|
|
|
tsp.enablePager( c, false );
|
2013-10-18 03:59:07 +00:00
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
// p must have ajaxObject
|
2015-11-20 15:27:22 +00:00
|
|
|
p.ajaxObject = wo.pager_ajaxObject;
|
2015-07-23 04:29:51 +00:00
|
|
|
p.ajaxObject.url = wo.pager_ajaxUrl;
|
2013-10-18 03:59:07 +00:00
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
if ( typeof wo.pager_ajaxUrl === 'string' ) {
|
|
|
|
// ajax pager; interact with database
|
|
|
|
p.ajax = true;
|
2015-11-20 15:27:22 +00:00
|
|
|
// When filtering with ajax, allow only custom filtering function, disable default filtering
|
|
|
|
// since it will be done server side.
|
2015-07-23 04:29:51 +00:00
|
|
|
wo.filter_serversideFiltering = true;
|
|
|
|
c.serverSideSorting = true;
|
2015-11-20 15:27:22 +00:00
|
|
|
tsp.moveToPage( c, p );
|
2015-07-23 04:29:51 +00:00
|
|
|
} else {
|
|
|
|
p.ajax = false;
|
|
|
|
// Regular pager; all rows stored in memory
|
2015-10-22 21:41:34 +00:00
|
|
|
ts.appendCache( c, true ); // true = don't apply widgets
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
2013-10-18 03:59:07 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
2015-11-20 15:27:22 +00:00
|
|
|
initComplete: function( c ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
var p = c.pager;
|
2015-11-20 15:27:22 +00:00
|
|
|
tsp.bindEvents( c );
|
|
|
|
if ( !p.ajax ) {
|
|
|
|
tsp.hideRowsSetup( c );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
2013-10-18 03:59:07 +00:00
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
// pager initialized
|
|
|
|
p.initialized = true;
|
|
|
|
p.initializing = false;
|
|
|
|
p.isInitializing = false;
|
2017-04-02 08:40:10 +00:00
|
|
|
tsp.setPageSize( c, p.size ); // page size 0 is ignored
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( c.debug ) {
|
|
|
|
console.log( 'Pager: Triggering pagerInitialized' );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
2015-12-02 01:38:56 +00:00
|
|
|
c.$table.triggerHandler( 'pagerInitialized', c );
|
2015-07-23 04:29:51 +00:00
|
|
|
// filter widget not initialized; it will update the output display & fire off the pagerComplete event
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( !( c.widgetOptions.filter_initialized && ts.hasWidget( c.table, 'filter' ) ) ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
// if ajax, then don't fire off pagerComplete
|
2015-11-20 15:27:22 +00:00
|
|
|
tsp.updatePageDisplay( c, !p.ajax );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
|
|
|
},
|
2013-10-18 03:59:07 +00:00
|
|
|
|
2015-11-20 15:27:22 +00:00
|
|
|
bindEvents: function( c ) {
|
2016-12-16 23:13:02 +00:00
|
|
|
var ctrls, fxn, tmp,
|
2015-07-23 04:29:51 +00:00
|
|
|
p = c.pager,
|
|
|
|
wo = c.widgetOptions,
|
|
|
|
namespace = c.namespace + 'pager',
|
|
|
|
s = wo.pager_selectors;
|
2014-11-03 20:44:08 +00:00
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
c.$table
|
2015-07-30 22:37:59 +00:00
|
|
|
.off( namespace )
|
2015-11-20 15:27:22 +00:00
|
|
|
.on( 'filterInit filterStart '.split( ' ' ).join( namespace + ' ' ), function( e, filters ) {
|
|
|
|
p.currentFilters = $.isArray( filters ) ? filters : c.$table.data( 'lastSearch' );
|
2015-07-23 04:29:51 +00:00
|
|
|
// don't change page if filters are the same (pager updating, etc)
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( e.type === 'filterStart' && wo.pager_pageReset !== false &&
|
2017-03-28 19:21:58 +00:00
|
|
|
( c.lastSearch || [] ).join( ',' ) !== ( p.currentFilters || [] ).join( ',' )
|
|
|
|
) {
|
2015-07-23 04:29:51 +00:00
|
|
|
p.page = wo.pager_pageReset; // fixes #456 & #565
|
|
|
|
}
|
|
|
|
})
|
|
|
|
// update pager after filter widget completes
|
2015-11-20 15:27:22 +00:00
|
|
|
.on( 'filterEnd sortEnd '.split( ' ' ).join( namespace + ' ' ), function() {
|
|
|
|
p.currentFilters = c.$table.data( 'lastSearch' );
|
|
|
|
if ( p.initialized || p.initializing ) {
|
|
|
|
if ( c.delayInit && c.rowsCopy && c.rowsCopy.length === 0 ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
// make sure we have a copy of all table rows once the cache has been built
|
2015-11-20 15:27:22 +00:00
|
|
|
tsp.updateCache( c );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
2015-11-20 15:27:22 +00:00
|
|
|
tsp.updatePageDisplay( c, false );
|
|
|
|
// tsp.moveToPage( c, p, false ); <-- called when applyWidgets is triggered
|
|
|
|
ts.applyWidget( c.table );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
|
|
|
})
|
2015-11-20 15:27:22 +00:00
|
|
|
.on( 'disablePager' + namespace, function( e ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
e.stopPropagation();
|
2015-11-20 15:27:22 +00:00
|
|
|
tsp.showAllRows( c );
|
2015-07-23 04:29:51 +00:00
|
|
|
})
|
2015-11-20 15:27:22 +00:00
|
|
|
.on( 'enablePager' + namespace, function( e ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
e.stopPropagation();
|
2015-11-20 15:27:22 +00:00
|
|
|
tsp.enablePager( c, true );
|
2015-07-23 04:29:51 +00:00
|
|
|
})
|
2015-11-20 15:27:22 +00:00
|
|
|
.on( 'destroyPager' + namespace, function( e, refreshing ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
e.stopPropagation();
|
2015-10-27 22:31:50 +00:00
|
|
|
// call removeWidget to make sure internal flags are modified.
|
2015-11-20 15:27:22 +00:00
|
|
|
ts.removeWidget( c.table, 'pager', false );
|
2015-07-23 04:29:51 +00:00
|
|
|
})
|
2015-11-20 15:27:22 +00:00
|
|
|
.on( 'updateComplete' + namespace, function( e, table, triggered ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
e.stopPropagation();
|
|
|
|
// table can be unintentionally undefined in tablesorter v2.17.7 and earlier
|
|
|
|
// don't recalculate total rows/pages if using ajax
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( !table || triggered || p.ajax ) { return; }
|
|
|
|
var $rows = c.$tbodies.eq( 0 ).children( 'tr' ).not( c.selectorRemove );
|
|
|
|
p.totalRows = $rows.length -
|
|
|
|
( wo.pager_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 );
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( $rows.length && c.rowsCopy && c.rowsCopy.length === 0 ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
// make a copy of all table rows once the cache has been built
|
2015-11-20 15:27:22 +00:00
|
|
|
tsp.updateCache( c );
|
2014-07-11 19:51:50 +00:00
|
|
|
}
|
2015-07-23 04:29:51 +00:00
|
|
|
if ( p.page >= p.totalPages ) {
|
2015-11-20 15:27:22 +00:00
|
|
|
tsp.moveToLastPage( c, p );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
2015-11-20 15:27:22 +00:00
|
|
|
tsp.hideRows( c );
|
|
|
|
tsp.changeHeight( c );
|
2015-07-23 04:29:51 +00:00
|
|
|
// update without triggering pagerComplete
|
2015-11-20 15:27:22 +00:00
|
|
|
tsp.updatePageDisplay( c, false );
|
2015-07-23 04:29:51 +00:00
|
|
|
// make sure widgets are applied - fixes #450
|
2015-10-22 21:41:34 +00:00
|
|
|
ts.applyWidget( table );
|
2015-11-20 15:27:22 +00:00
|
|
|
tsp.updatePageDisplay( c );
|
2015-07-23 04:29:51 +00:00
|
|
|
})
|
2015-11-20 15:27:22 +00:00
|
|
|
.on( 'pageSize refreshComplete '.split( ' ' ).join( namespace + ' ' ), function( e, size ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
e.stopPropagation();
|
2015-11-20 15:27:22 +00:00
|
|
|
tsp.setPageSize( c, tsp.parsePageSize( c, size, 'get' ) );
|
2017-04-02 08:40:10 +00:00
|
|
|
tsp.moveToPage( c, p, true );
|
2015-11-20 15:27:22 +00:00
|
|
|
tsp.hideRows( c );
|
|
|
|
tsp.updatePageDisplay( c, false );
|
2015-07-23 04:29:51 +00:00
|
|
|
})
|
2015-11-20 15:27:22 +00:00
|
|
|
.on( 'pageSet pagerUpdate '.split( ' ' ).join( namespace + ' ' ), function( e, num ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
e.stopPropagation();
|
|
|
|
// force pager refresh
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( e.type === 'pagerUpdate' ) {
|
2015-10-26 01:55:48 +00:00
|
|
|
num = typeof num === 'undefined' ? p.page + 1 : num;
|
2015-07-23 04:29:51 +00:00
|
|
|
p.last.page = true;
|
2013-10-18 03:59:07 +00:00
|
|
|
}
|
2015-11-20 15:27:22 +00:00
|
|
|
p.page = ( parseInt( num, 10 ) || 1 ) - 1;
|
|
|
|
tsp.moveToPage( c, p, true );
|
|
|
|
tsp.updatePageDisplay( c, false );
|
2015-07-23 04:29:51 +00:00
|
|
|
})
|
2015-11-20 15:27:22 +00:00
|
|
|
.on( 'pageAndSize' + namespace, function( e, page, size ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
e.stopPropagation();
|
2015-11-20 15:27:22 +00:00
|
|
|
p.page = ( parseInt(page, 10) || 1 ) - 1;
|
|
|
|
tsp.setPageSize( c, tsp.parsePageSize( c, size, 'get' ) );
|
|
|
|
tsp.moveToPage( c, p, true );
|
|
|
|
tsp.hideRows( c );
|
|
|
|
tsp.updatePageDisplay( c, false );
|
2013-10-18 03:59:07 +00:00
|
|
|
});
|
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
// clicked controls
|
|
|
|
ctrls = [ s.first, s.prev, s.next, s.last ];
|
|
|
|
fxn = [ 'moveToFirstPage', 'moveToPrevPage', 'moveToNextPage', 'moveToLastPage' ];
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( c.debug && !p.$container.length ) {
|
|
|
|
console.warn( 'Pager: >> Container not found' );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
2015-11-20 15:27:22 +00:00
|
|
|
p.$container.find( ctrls.join( ',' ) )
|
|
|
|
.attr( 'tabindex', 0 )
|
|
|
|
.off( 'click' + namespace )
|
|
|
|
.on( 'click' + namespace, function( e ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
e.stopPropagation();
|
|
|
|
var i,
|
2015-11-20 15:27:22 +00:00
|
|
|
$c = $( this ),
|
2015-07-23 04:29:51 +00:00
|
|
|
l = ctrls.length;
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( !$c.hasClass( wo.pager_css.disabled ) ) {
|
|
|
|
for ( i = 0; i < l; i++ ) {
|
|
|
|
if ( $c.is( ctrls[ i ] ) ) {
|
|
|
|
tsp[ fxn[ i ] ]( c, p );
|
2015-07-23 04:29:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-10-18 03:59:07 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-12-16 23:13:02 +00:00
|
|
|
tmp = p.$container.find( wo.pager_selectors.gotoPage );
|
|
|
|
if ( tmp.length ) {
|
|
|
|
tmp
|
2015-11-20 15:27:22 +00:00
|
|
|
.off( 'change' + namespace )
|
|
|
|
.on( 'change' + namespace, function() {
|
|
|
|
p.page = $( this ).val() - 1;
|
|
|
|
tsp.moveToPage( c, p, true );
|
|
|
|
tsp.updatePageDisplay( c, false );
|
2015-07-23 04:29:51 +00:00
|
|
|
});
|
2015-11-20 15:27:22 +00:00
|
|
|
} else if ( c.debug ) {
|
|
|
|
console.warn( 'Pager: >> Goto selector not found' );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
|
|
|
|
2016-12-16 23:13:02 +00:00
|
|
|
tmp = p.$container.find( wo.pager_selectors.pageSize );
|
|
|
|
if ( tmp.length ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
// setting an option as selected appears to cause issues with initial page size
|
2016-12-16 23:13:02 +00:00
|
|
|
tmp.find( 'option' ).removeAttr( 'selected' );
|
|
|
|
tmp
|
2015-11-20 15:27:22 +00:00
|
|
|
.off( 'change' + namespace )
|
|
|
|
.on( 'change' + namespace, function() {
|
|
|
|
if ( !$( this ).hasClass( wo.pager_css.disabled ) ) {
|
|
|
|
var size = $( this ).val();
|
2016-12-16 23:13:02 +00:00
|
|
|
// in case there are more than one pager
|
|
|
|
p.$container.find( wo.pager_selectors.pageSize ).val( size );
|
2015-11-20 15:27:22 +00:00
|
|
|
tsp.setPageSize( c, size );
|
2017-04-02 08:40:10 +00:00
|
|
|
tsp.moveToPage( c, p, true );
|
2015-11-20 15:27:22 +00:00
|
|
|
tsp.changeHeight( c );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
2015-11-20 15:27:22 +00:00
|
|
|
} else if ( c.debug ) {
|
2015-07-24 23:23:00 +00:00
|
|
|
console.warn('Pager: >> Size selector not found');
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
// hide arrows at extremes
|
2015-11-20 15:27:22 +00:00
|
|
|
pagerArrows: function( c, disable ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
var p = c.pager,
|
|
|
|
dis = !!disable,
|
|
|
|
first = dis || p.page === 0,
|
2015-11-19 15:41:35 +00:00
|
|
|
tp = tsp.getTotalPages( c, p ),
|
2015-07-23 04:29:51 +00:00
|
|
|
last = dis || p.page === tp - 1 || tp === 0,
|
|
|
|
wo = c.widgetOptions,
|
|
|
|
s = wo.pager_selectors;
|
|
|
|
if ( wo.pager_updateArrows ) {
|
2015-11-20 15:27:22 +00:00
|
|
|
p.$container
|
|
|
|
.find( s.first + ',' + s.prev )
|
|
|
|
.toggleClass( wo.pager_css.disabled, first )
|
2016-11-26 15:57:00 +00:00
|
|
|
.prop( 'aria-disabled', first );
|
2015-11-20 15:27:22 +00:00
|
|
|
p.$container
|
|
|
|
.find( s.next + ',' + s.last )
|
|
|
|
.toggleClass( wo.pager_css.disabled, last )
|
2016-11-26 15:57:00 +00:00
|
|
|
.prop( 'aria-disabled', last );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-11-19 00:58:50 +00:00
|
|
|
calcFilters: function( c ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
var normalized, indx, len,
|
|
|
|
wo = c.widgetOptions,
|
|
|
|
p = c.pager,
|
2015-11-20 15:27:22 +00:00
|
|
|
hasFilters = c.$table.hasClass( 'hasFilters' );
|
2016-08-17 17:04:28 +00:00
|
|
|
if ( hasFilters && !p.ajax ) {
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( $.isEmptyObject( c.cache ) ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
// delayInit: true so nothing is in the cache
|
2015-11-20 15:27:22 +00:00
|
|
|
p.filteredRows = p.totalRows = c.$tbodies.eq( 0 )
|
|
|
|
.children( 'tr' )
|
|
|
|
.not( wo.pager_countChildRows ? '' : '.' + c.cssChildRow )
|
|
|
|
.length;
|
2015-07-23 04:29:51 +00:00
|
|
|
} else {
|
|
|
|
p.filteredRows = 0;
|
2015-11-20 15:27:22 +00:00
|
|
|
normalized = c.cache[ 0 ].normalized;
|
2015-07-23 04:29:51 +00:00
|
|
|
len = normalized.length;
|
2015-11-20 15:27:22 +00:00
|
|
|
for ( indx = 0; indx < len; indx++ ) {
|
|
|
|
p.filteredRows += p.regexRows.test( normalized[ indx ][ c.columns ].$row[ 0 ].className ) ? 0 : 1;
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
2015-02-26 00:43:59 +00:00
|
|
|
}
|
2015-11-20 15:27:22 +00:00
|
|
|
} else if ( !hasFilters ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
p.filteredRows = p.totalRows;
|
2014-07-11 19:51:50 +00:00
|
|
|
}
|
2015-07-23 04:29:51 +00:00
|
|
|
},
|
|
|
|
|
2015-11-20 15:27:22 +00:00
|
|
|
updatePageDisplay: function( c, completed ) {
|
2016-02-15 18:01:19 +00:00
|
|
|
if ( c.pager && c.pager.initializing ) { return; }
|
2016-12-30 22:52:19 +00:00
|
|
|
var s, t, $out, options, indx, len, output,
|
2015-11-20 15:27:22 +00:00
|
|
|
table = c.table,
|
2015-07-23 04:29:51 +00:00
|
|
|
wo = c.widgetOptions,
|
|
|
|
p = c.pager,
|
|
|
|
namespace = c.namespace + 'pager',
|
2015-10-30 21:13:36 +00:00
|
|
|
sz = tsp.parsePageSize( c, p.size, 'get' ); // don't allow dividing by zero
|
2016-05-01 20:25:01 +00:00
|
|
|
if ( sz === 'all' ) { sz = p.totalRows; }
|
2016-02-22 03:47:59 +00:00
|
|
|
if ( wo.pager_countChildRows ) { t[ t.length ] = c.cssChildRow; }
|
2016-12-16 23:13:02 +00:00
|
|
|
p.$container.find( wo.pager_selectors.pageSize + ',' + wo.pager_selectors.gotoPage )
|
2015-11-20 15:27:22 +00:00
|
|
|
.removeClass( wo.pager_css.disabled )
|
|
|
|
.removeAttr( 'disabled' )
|
2016-11-26 15:57:00 +00:00
|
|
|
.prop( 'aria-disabled', 'false' );
|
2015-07-23 04:29:51 +00:00
|
|
|
p.totalPages = Math.ceil( p.totalRows / sz ); // needed for 'pageSize' method
|
|
|
|
c.totalRows = p.totalRows;
|
2015-11-19 00:58:50 +00:00
|
|
|
tsp.parsePageNumber( c, p );
|
|
|
|
tsp.calcFilters( c );
|
2015-07-23 04:29:51 +00:00
|
|
|
c.filteredRows = p.filteredRows;
|
|
|
|
p.filteredPages = Math.ceil( p.filteredRows / sz ) || 0;
|
2015-11-19 15:41:35 +00:00
|
|
|
if ( tsp.getTotalPages( c, p ) >= 0 ) {
|
2016-05-01 20:25:01 +00:00
|
|
|
t = ( sz * p.page > p.filteredRows ) && completed;
|
2015-11-20 15:27:22 +00:00
|
|
|
p.page = t ? wo.pager_pageReset || 0 : p.page;
|
2016-05-01 20:25:01 +00:00
|
|
|
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 ) );
|
2015-11-20 15:27:22 +00:00
|
|
|
$out = p.$container.find( wo.pager_selectors.pageDisplay );
|
2016-09-09 11:30:00 +00:00
|
|
|
|
|
|
|
// Output param can be callback for custom rendering or string
|
|
|
|
if ( typeof wo.pager_output === 'function' ) {
|
|
|
|
s = wo.pager_output( table, p );
|
|
|
|
} else {
|
2016-12-30 22:52:19 +00:00
|
|
|
output = $out
|
|
|
|
// get output template from data-pager-output or data-pager-output-filtered
|
|
|
|
.attr('data-pager-output' + (p.filteredRows < p.totalRows ? '-filtered' : '')) ||
|
|
|
|
wo.pager_output;
|
2016-09-09 11:30:00 +00:00
|
|
|
// form the output string (can now get a new output string from the server)
|
2016-12-30 22:52:19 +00:00
|
|
|
s = ( p.ajaxData && p.ajaxData.output ? p.ajaxData.output || output : output )
|
2016-09-09 11:30:00 +00:00
|
|
|
// {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;
|
|
|
|
})
|
|
|
|
// {totalPages}, {extra}, {extra:0} (array) or {extra : key} (object)
|
|
|
|
.replace( /\{\w+(\s*:\s*\w+)?\}/gi, function( m ) {
|
|
|
|
var len, indx,
|
|
|
|
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 : '';
|
|
|
|
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 + '"/>';
|
|
|
|
}
|
|
|
|
return extra.length > 1 && data && data[ extra[ 0 ] ] ?
|
|
|
|
data[ extra[ 0 ] ][ extra[ 1 ] ] :
|
|
|
|
p[ str ] || ( data ? data[ str ] : deflt ) || deflt;
|
|
|
|
});
|
|
|
|
}
|
2016-12-16 23:13:02 +00:00
|
|
|
if ( p.$container.find( wo.pager_selectors.gotoPage ).length ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
t = '';
|
2015-11-20 15:27:22 +00:00
|
|
|
options = tsp.buildPageSelect( c, p );
|
2015-07-23 04:29:51 +00:00
|
|
|
len = options.length;
|
2015-11-20 15:27:22 +00:00
|
|
|
for ( indx = 0; indx < len; indx++ ) {
|
|
|
|
t += '<option value="' + options[ indx ] + '">' + options[ indx ] + '</option>';
|
2014-07-22 12:42:15 +00:00
|
|
|
}
|
2015-07-23 04:29:51 +00:00
|
|
|
// innerHTML doesn't work in IE9 - http://support2.microsoft.com/kb/276228
|
2016-12-16 23:13:02 +00:00
|
|
|
p.$container.find( wo.pager_selectors.gotoPage ).html( t ).val( p.page + 1 );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( $out.length ) {
|
|
|
|
$out[ ($out[ 0 ].nodeName === 'INPUT' ) ? 'val' : 'html' ]( s );
|
2015-07-23 04:29:51 +00:00
|
|
|
// rebind startRow/page inputs
|
2015-11-20 15:27:22 +00:00
|
|
|
$out
|
|
|
|
.find( '.ts-startRow, .ts-page' )
|
|
|
|
.off( 'change' + namespace )
|
|
|
|
.on( '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;
|
2015-12-02 01:38:56 +00:00
|
|
|
c.$table.triggerHandler( 'pageSet' + namespace, [ pg ] );
|
2015-11-20 15:27:22 +00:00
|
|
|
});
|
2015-02-26 00:43:59 +00:00
|
|
|
}
|
2015-02-04 13:29:07 +00:00
|
|
|
}
|
2015-11-20 15:27:22 +00:00
|
|
|
tsp.pagerArrows( c );
|
|
|
|
tsp.fixHeight( c );
|
|
|
|
if ( p.initialized && completed !== false ) {
|
|
|
|
if ( c.debug ) {
|
|
|
|
console.log( 'Pager: Triggering pagerComplete' );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
2015-12-02 01:38:56 +00:00
|
|
|
c.$table.triggerHandler( 'pagerComplete', c );
|
2015-07-23 04:29:51 +00:00
|
|
|
// save pager info to storage
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( wo.pager_savePages && ts.storage ) {
|
|
|
|
ts.storage( table, wo.pager_storageKey, {
|
2015-07-23 04:29:51 +00:00
|
|
|
page : p.page,
|
2016-05-01 20:25:01 +00:00
|
|
|
size : sz === p.totalRows ? 'all' : sz
|
2015-07-23 04:29:51 +00:00
|
|
|
});
|
|
|
|
}
|
2013-10-18 03:59:07 +00:00
|
|
|
}
|
2015-07-23 04:29:51 +00:00
|
|
|
},
|
|
|
|
|
2015-11-20 15:27:22 +00:00
|
|
|
buildPageSelect: function( c, p ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
// Filter the options page number link array if it's larger than 'pager_maxOptionSize'
|
|
|
|
// as large page set links will slow the browser on large dom inserts
|
2015-11-20 15:27:22 +00:00
|
|
|
var i, centralFocusSize, focusOptionPages, insertIndex, optionLength, focusLength,
|
2015-07-23 04:29:51 +00:00
|
|
|
wo = c.widgetOptions,
|
2015-11-19 15:41:35 +00:00
|
|
|
pg = tsp.getTotalPages( c, p ) || 1,
|
2015-07-23 04:29:51 +00:00
|
|
|
// make skip set size multiples of 5
|
2015-11-20 15:27:22 +00:00
|
|
|
skipSetSize = Math.ceil( ( pg / wo.pager_maxOptionSize ) / 5 ) * 5,
|
|
|
|
largeCollection = pg > wo.pager_maxOptionSize,
|
|
|
|
currentPage = p.page + 1,
|
|
|
|
startPage = skipSetSize,
|
|
|
|
endPage = pg - skipSetSize,
|
|
|
|
optionPages = [ 1 ],
|
2015-07-23 04:29:51 +00:00
|
|
|
// construct default options pages array
|
2015-11-20 15:27:22 +00:00
|
|
|
optionPagesStartPage = largeCollection ? skipSetSize : 1;
|
2015-07-23 04:29:51 +00:00
|
|
|
|
2015-11-20 15:27:22 +00:00
|
|
|
for ( i = optionPagesStartPage; i <= pg; ) {
|
2016-02-22 03:47:59 +00:00
|
|
|
optionPages[ optionPages.length ] = i;
|
2015-11-20 15:27:22 +00:00
|
|
|
i = i + ( largeCollection ? skipSetSize : 1 );
|
2015-02-27 23:37:14 +00:00
|
|
|
}
|
2016-02-22 03:47:59 +00:00
|
|
|
optionPages[ optionPages.length ] = pg;
|
2015-07-23 04:29:51 +00:00
|
|
|
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( largeCollection ) {
|
|
|
|
focusOptionPages = [];
|
2015-07-23 04:29:51 +00:00
|
|
|
// don't allow central focus size to be > 5 on either side of current page
|
2015-11-20 15:27:22 +00:00
|
|
|
centralFocusSize = Math.max( Math.floor( wo.pager_maxOptionSize / skipSetSize ) - 1, 5 );
|
2015-07-23 04:29:51 +00:00
|
|
|
|
2015-11-20 15:27:22 +00:00
|
|
|
startPage = currentPage - centralFocusSize;
|
|
|
|
if ( startPage < 1 ) { startPage = 1; }
|
|
|
|
endPage = currentPage + centralFocusSize;
|
|
|
|
if ( endPage > pg ) { endPage = pg; }
|
2015-07-23 04:29:51 +00:00
|
|
|
// construct an array to get a focus set around the current page
|
2015-11-20 15:27:22 +00:00
|
|
|
for ( i = startPage; i <= endPage ; i++ ) {
|
2016-02-22 03:47:59 +00:00
|
|
|
focusOptionPages[ focusOptionPages.length ] = i;
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// keep unique values
|
2015-11-20 15:27:22 +00:00
|
|
|
optionPages = $.grep( optionPages, function( value, indx ) {
|
|
|
|
return $.inArray( value, optionPages ) === indx;
|
2013-10-18 03:59:07 +00:00
|
|
|
});
|
2015-07-23 04:29:51 +00:00
|
|
|
|
2015-11-20 15:27:22 +00:00
|
|
|
optionLength = optionPages.length;
|
|
|
|
focusLength = focusOptionPages.length;
|
2015-07-23 04:29:51 +00:00
|
|
|
|
2015-11-20 15:27:22 +00:00
|
|
|
// make sure at all optionPages aren't replaced
|
|
|
|
if ( optionLength - focusLength > skipSetSize / 2 && optionLength + focusLength > wo.pager_maxOptionSize ) {
|
|
|
|
insertIndex = Math.floor( optionLength / 2 ) - Math.floor( focusLength / 2 );
|
|
|
|
Array.prototype.splice.apply( optionPages, [ insertIndex, focusLength ] );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
2015-11-20 15:27:22 +00:00
|
|
|
optionPages = optionPages.concat( focusOptionPages );
|
2015-07-23 04:29:51 +00:00
|
|
|
|
2014-09-17 06:45:27 +00:00
|
|
|
}
|
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
// keep unique values again
|
2015-11-20 15:27:22 +00:00
|
|
|
optionPages = $.grep( optionPages, function( value, indx ) {
|
|
|
|
return $.inArray( value, optionPages ) === indx;
|
2015-07-23 04:29:51 +00:00
|
|
|
})
|
2015-11-20 15:27:22 +00:00
|
|
|
.sort( function( a, b ) {
|
|
|
|
return a - b;
|
|
|
|
});
|
2014-09-17 06:45:27 +00:00
|
|
|
|
2015-11-20 15:27:22 +00:00
|
|
|
return optionPages;
|
2015-07-23 04:29:51 +00:00
|
|
|
},
|
2014-09-17 06:45:27 +00:00
|
|
|
|
2015-11-20 15:27:22 +00:00
|
|
|
fixHeight: function( c ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
var d, h,
|
2015-11-20 15:27:22 +00:00
|
|
|
table = c.table,
|
2015-07-23 04:29:51 +00:00
|
|
|
p = c.pager,
|
|
|
|
wo = c.widgetOptions,
|
2015-11-20 15:27:22 +00:00
|
|
|
$b = c.$tbodies.eq( 0 );
|
|
|
|
$b.find( 'tr.pagerSavedHeightSpacer' ).remove();
|
|
|
|
if ( wo.pager_fixedHeight && !p.isDisabled ) {
|
|
|
|
h = $.data( table, 'pagerSavedHeight' );
|
|
|
|
if ( h ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
d = h - $b.height();
|
2016-05-01 20:25:01 +00:00
|
|
|
if ( d > 5 && $.data( table, 'pagerLastSize' ) === p.size &&
|
|
|
|
$b.children( 'tr:visible' ).length < ( p.size === 'all' ? p.totalRows : p.size ) ) {
|
2015-11-20 15:27:22 +00:00
|
|
|
$b.append( '<tr class="pagerSavedHeightSpacer ' + c.selectorRemove.slice( 1 ) +
|
|
|
|
'" style="height:' + d + 'px;"></tr>' );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
|
|
|
}
|
2014-09-17 06:45:27 +00:00
|
|
|
}
|
2015-07-23 04:29:51 +00:00
|
|
|
},
|
2014-09-17 06:45:27 +00:00
|
|
|
|
2015-11-20 15:27:22 +00:00
|
|
|
changeHeight: function( c ) {
|
|
|
|
var h,
|
|
|
|
table = c.table,
|
2016-05-01 20:25:01 +00:00
|
|
|
p = c.pager,
|
|
|
|
sz = p.size === 'all' ? p.totalRows : p.size,
|
2015-11-20 15:27:22 +00:00
|
|
|
$b = c.$tbodies.eq( 0 );
|
|
|
|
$b.find( 'tr.pagerSavedHeightSpacer' ).remove();
|
|
|
|
if ( !$b.children( 'tr:visible' ).length ) {
|
|
|
|
$b.append( '<tr class="pagerSavedHeightSpacer ' + c.selectorRemove.slice( 1 ) + '"><td> </td></tr>' );
|
2013-10-18 03:59:07 +00:00
|
|
|
}
|
2016-05-01 20:25:01 +00:00
|
|
|
h = $b.children( 'tr' ).eq( 0 ).height() * sz;
|
2015-11-20 15:27:22 +00:00
|
|
|
$.data( table, 'pagerSavedHeight', h );
|
|
|
|
tsp.fixHeight( c );
|
2016-05-01 20:25:01 +00:00
|
|
|
$.data( table, 'pagerLastSize', p.size );
|
2015-07-23 04:29:51 +00:00
|
|
|
},
|
2013-10-18 03:59:07 +00:00
|
|
|
|
2015-11-20 15:27:22 +00:00
|
|
|
hideRows: function( c ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
if ( !c.widgetOptions.pager_ajaxUrl ) {
|
|
|
|
var tbodyIndex, rowIndex, $rows, len, lastIndex,
|
2015-11-20 15:27:22 +00:00
|
|
|
table = c.table,
|
2015-07-23 04:29:51 +00:00
|
|
|
p = c.pager,
|
|
|
|
wo = c.widgetOptions,
|
|
|
|
tbodyLen = c.$tbodies.length,
|
2016-05-01 20:25:01 +00:00
|
|
|
sz = p.size === 'all' ? p.totalRows : p.size,
|
|
|
|
start = ( p.page * sz ),
|
|
|
|
end = start + sz,
|
2015-07-23 04:29:51 +00:00
|
|
|
last = 0, // for cache indexing
|
|
|
|
size = 0; // size counter
|
|
|
|
p.cacheIndex = [];
|
|
|
|
for ( tbodyIndex = 0; tbodyIndex < tbodyLen; tbodyIndex++ ) {
|
|
|
|
$rows = c.$tbodies.eq( tbodyIndex ).children( 'tr' );
|
|
|
|
len = $rows.length;
|
|
|
|
lastIndex = 0;
|
|
|
|
last = 0; // for cache indexing
|
|
|
|
size = 0; // size counter
|
|
|
|
for ( rowIndex = 0; rowIndex < len; rowIndex++ ) {
|
2016-06-28 09:28:35 +00:00
|
|
|
if ( !p.regexFiltered.test( $rows[ rowIndex ].className ) ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
if ( size === start && $rows[ rowIndex ].className.match( c.cssChildRow ) ) {
|
|
|
|
// hide child rows @ start of pager (if already visible)
|
|
|
|
$rows[ rowIndex ].style.display = 'none';
|
|
|
|
} else {
|
|
|
|
$rows[ rowIndex ].style.display = ( size >= start && size < end ) ? '' : 'none';
|
|
|
|
if ( last !== size && size >= start && size < end ) {
|
2016-02-22 03:47:59 +00:00
|
|
|
p.cacheIndex[ p.cacheIndex.length ] = rowIndex;
|
2015-07-23 04:29:51 +00:00
|
|
|
last = size;
|
|
|
|
}
|
|
|
|
// don't count child rows
|
|
|
|
size += $rows[ rowIndex ].className
|
|
|
|
.match( c.cssChildRow + '|' + c.selectorRemove.slice( 1 ) ) && !wo.pager_countChildRows ? 0 : 1;
|
|
|
|
if ( size === end && $rows[ rowIndex ].style.display !== 'none' &&
|
|
|
|
$rows[ rowIndex ].className.match( ts.css.cssHasChild ) ) {
|
|
|
|
lastIndex = rowIndex;
|
|
|
|
}
|
2015-07-15 02:22:52 +00:00
|
|
|
}
|
2014-03-31 10:07:19 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-23 04:29:51 +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 < len && $rows[ lastIndex ].className.match( c.cssChildRow ) ) {
|
|
|
|
$rows[ lastIndex ].style.display = '';
|
|
|
|
}
|
2015-07-15 02:22:52 +00:00
|
|
|
}
|
2013-10-18 03:59:07 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-23 04:29:51 +00:00
|
|
|
},
|
|
|
|
|
2015-11-20 15:27:22 +00:00
|
|
|
hideRowsSetup: function( c ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
var p = c.pager,
|
2015-10-26 01:55:48 +00:00
|
|
|
namespace = c.namespace + 'pager',
|
2016-12-30 22:52:19 +00:00
|
|
|
$el = p.$container.find( c.widgetOptions.pager_selectors.pageSize ),
|
2016-12-16 23:13:02 +00:00
|
|
|
size = $el.val();
|
2015-10-30 21:13:36 +00:00
|
|
|
p.size = tsp.parsePageSize( c, size, 'get' );
|
2017-04-02 08:40:10 +00:00
|
|
|
tsp.setPageSize( c, p.size );
|
2015-11-20 15:27:22 +00:00
|
|
|
tsp.pagerArrows( c );
|
2015-07-23 04:29:51 +00:00
|
|
|
if ( !c.widgetOptions.pager_removeRows ) {
|
2015-11-20 15:27:22 +00:00
|
|
|
tsp.hideRows( c );
|
|
|
|
c.$table.on( 'sortEnd filterEnd '.split( ' ' ).join( namespace + ' ' ), function() {
|
|
|
|
tsp.hideRows( c );
|
2015-07-23 04:29:51 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-11-20 15:27:22 +00:00
|
|
|
renderAjax: function( data, c, xhr, settings, exception ) {
|
|
|
|
var table = c.table,
|
|
|
|
p = c.pager,
|
2015-07-23 04:29:51 +00:00
|
|
|
wo = c.widgetOptions;
|
|
|
|
// process data
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( $.isFunction( wo.pager_ajaxProcessing ) ) {
|
2015-11-09 17:42:42 +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
|
2015-11-20 15:27:22 +00:00
|
|
|
c.$tbodies.eq( 0 ).empty();
|
2015-11-09 17:42:42 +00:00
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
// ajaxProcessing result: [ total, rows, headers ]
|
2016-05-01 20:25:01 +00:00
|
|
|
var i, j, t, hsh, $f, $sh, $headers, $h, icon, th, d, l, rr_count, len, sz,
|
2015-07-23 04:29:51 +00:00
|
|
|
$table = c.$table,
|
|
|
|
tds = '',
|
2015-11-20 15:27:22 +00:00
|
|
|
result = wo.pager_ajaxProcessing( data, table, xhr ) || [ 0, [] ],
|
|
|
|
hl = $table.find( 'thead th' ).length;
|
2015-07-23 04:29:51 +00:00
|
|
|
|
|
|
|
// Clean up any previous error.
|
2015-08-15 15:56:42 +00:00
|
|
|
ts.showError( table );
|
2015-07-23 04:29:51 +00:00
|
|
|
|
|
|
|
if ( exception ) {
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( c.debug ) {
|
|
|
|
console.error( 'Pager: >> Ajax Error', xhr, settings, exception );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
2015-08-19 21:33:32 +00:00
|
|
|
ts.showError( table, xhr, settings, exception );
|
2015-11-20 15:27:22 +00:00
|
|
|
c.$tbodies.eq( 0 ).children( 'tr' ).detach();
|
2015-07-23 04:29:51 +00:00
|
|
|
p.totalRows = 0;
|
2013-10-18 03:59:07 +00:00
|
|
|
} else {
|
2015-07-23 04:29:51 +00:00
|
|
|
// process ajax object
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( !$.isArray( result ) ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
p.ajaxData = result;
|
|
|
|
c.totalRows = p.totalRows = result.total;
|
2015-11-20 15:27:22 +00:00
|
|
|
c.filteredRows = p.filteredRows = typeof result.filteredRows !== 'undefined' ?
|
|
|
|
result.filteredRows :
|
|
|
|
result.total;
|
2015-07-23 04:29:51 +00:00
|
|
|
th = result.headers;
|
|
|
|
d = result.rows || [];
|
|
|
|
} else {
|
|
|
|
// allow [ total, rows, headers ] or [ rows, total, headers ]
|
2015-11-20 15:27:22 +00:00
|
|
|
t = isNaN( result[ 0 ] ) && !isNaN( result[ 1 ] );
|
2015-07-23 04:29:51 +00:00
|
|
|
// ensure a zero returned row count doesn't fail the logical ||
|
2015-11-20 15:27:22 +00:00
|
|
|
rr_count = result[ t ? 1 : 0 ];
|
|
|
|
p.totalRows = isNaN( rr_count ) ? p.totalRows || 0 : rr_count;
|
2015-07-23 04:29:51 +00:00
|
|
|
// 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
|
2015-11-20 15:27:22 +00:00
|
|
|
d = p.totalRows === 0 ? [] : result[ t ? 0 : 1 ] || []; // row data
|
|
|
|
th = result[ 2 ]; // headers
|
2014-04-09 12:24:17 +00:00
|
|
|
}
|
2015-07-23 04:29:51 +00:00
|
|
|
l = d && d.length;
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( d instanceof jQuery ) {
|
|
|
|
if ( wo.pager_processAjaxOnInit ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
// append jQuery object
|
2015-11-20 15:27:22 +00:00
|
|
|
c.$tbodies.eq( 0 ).empty();
|
|
|
|
c.$tbodies.eq( 0 ).append( d );
|
2013-10-18 03:59:07 +00:00
|
|
|
}
|
2015-11-20 15:27:22 +00:00
|
|
|
} else if ( l ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
// 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
|
2015-11-20 15:27:22 +00:00
|
|
|
tds += /^\s*<td/.test( d[ i ][ j ] ) ? $.trim( d[ i ][ j ] ) : '<td>' + d[ i ][ j ] + '</td>';
|
2013-10-18 03:59:07 +00:00
|
|
|
}
|
2015-07-23 04:29:51 +00:00
|
|
|
tds += '</tr>';
|
|
|
|
}
|
|
|
|
// add rows to first tbody
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( wo.pager_processAjaxOnInit ) {
|
|
|
|
c.$tbodies.eq( 0 ).html( tds );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
wo.pager_processAjaxOnInit = true;
|
2016-12-29 10:11:20 +00:00
|
|
|
// update new header text
|
|
|
|
if ( th ) {
|
|
|
|
hsh = $table.hasClass( 'hasStickyHeaders' );
|
|
|
|
$sh = hsh ?
|
|
|
|
wo.$sticky.children( 'thead:first' ).children( 'tr:not(.' + c.cssIgnoreRow + ')' ).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( '.' + ts.css.headerIn ).html( th[ j ] ).append( icon );
|
|
|
|
if ( hsh && $sh.length ) {
|
|
|
|
icon = $sh.eq( j ).find( '.' + ts.css.icon ).clone( true );
|
|
|
|
$sh.eq( j ).find( '.' + ts.css.headerIn ).html( th[ j ] ).append( icon );
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$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 );
|
|
|
|
$sh.eq( j ).find( '.' + ts.css.headerIn ).html( th[ j ] );
|
|
|
|
}
|
2013-10-18 03:59:07 +00:00
|
|
|
}
|
2016-12-29 10:11:20 +00:00
|
|
|
$f.eq( j ).html( th[ j ] );
|
|
|
|
}
|
|
|
|
if ( hsh ) {
|
|
|
|
tsp.bindEvents( c );
|
2013-10-18 03:59:07 +00:00
|
|
|
}
|
2015-05-17 16:10:49 +00:00
|
|
|
}
|
2013-10-18 03:59:07 +00:00
|
|
|
}
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( c.showProcessing ) {
|
|
|
|
ts.isProcessing( table ); // remove loading icon
|
2013-12-13 00:46:45 +00:00
|
|
|
}
|
2016-05-01 20:25:01 +00:00
|
|
|
sz = tsp.parsePageSize( c, p.size, 'get' );
|
2015-07-23 04:29:51 +00:00
|
|
|
// make sure last pager settings are saved, prevents multiple server side calls with
|
|
|
|
// the same parameters
|
2016-05-01 20:25:01 +00:00
|
|
|
p.totalPages = sz === 'all' ? 1 : Math.ceil( p.totalRows / sz );
|
2015-07-23 04:29:51 +00:00
|
|
|
p.last.totalRows = p.totalRows;
|
|
|
|
p.last.currentFilters = p.currentFilters;
|
2015-11-20 15:27:22 +00:00
|
|
|
p.last.sortList = ( c.sortList || [] ).join( ',' );
|
2015-07-23 04:29:51 +00:00
|
|
|
p.initializing = false;
|
|
|
|
// update display without triggering pager complete... before updating cache
|
2015-11-20 15:27:22 +00:00
|
|
|
tsp.updatePageDisplay( c, false );
|
2015-10-22 21:41:34 +00:00
|
|
|
// tablesorter core updateCache (not pager)
|
2015-11-20 15:27:22 +00:00
|
|
|
ts.updateCache( c, function() {
|
|
|
|
if ( p.initialized ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
// apply widgets after table has rendered & after a delay to prevent
|
|
|
|
// multiple applyWidget blocking code from blocking this trigger
|
2015-11-20 15:27:22 +00:00
|
|
|
setTimeout( function() {
|
|
|
|
if ( c.debug ) {
|
|
|
|
console.log( 'Pager: Triggering pagerChange' );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
2015-12-02 01:38:56 +00:00
|
|
|
$table.triggerHandler( 'pagerChange', p );
|
2015-10-22 21:41:34 +00:00
|
|
|
ts.applyWidget( table );
|
2015-11-20 15:27:22 +00:00
|
|
|
tsp.updatePageDisplay( c );
|
|
|
|
}, 0 );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
2015-10-22 21:41:34 +00:00
|
|
|
});
|
2013-10-18 03:59:07 +00:00
|
|
|
}
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( !p.initialized ) {
|
2015-10-22 21:41:34 +00:00
|
|
|
ts.applyWidget( table );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-11-20 15:27:22 +00:00
|
|
|
getAjax: function( c ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
var counter,
|
2015-11-20 15:27:22 +00:00
|
|
|
url = tsp.getAjaxUrl( c ),
|
|
|
|
$doc = $( document ),
|
2015-07-23 04:29:51 +00:00
|
|
|
namespace = c.namespace + 'pager',
|
|
|
|
p = c.pager;
|
|
|
|
if ( url !== '' ) {
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( c.showProcessing ) {
|
|
|
|
ts.isProcessing( c.table, true ); // show loading icon
|
2013-11-27 17:07:52 +00:00
|
|
|
}
|
2015-11-20 15:27:22 +00:00
|
|
|
$doc.on( 'ajaxError' + namespace, function( e, xhr, settings, exception ) {
|
|
|
|
tsp.renderAjax( null, c, xhr, settings, exception );
|
|
|
|
$doc.off( 'ajaxError' + namespace );
|
2015-07-23 04:29:51 +00:00
|
|
|
});
|
|
|
|
counter = ++p.ajaxCounter;
|
|
|
|
p.last.ajaxUrl = url; // remember processed url
|
|
|
|
p.ajaxObject.url = url; // from the ajaxUrl option and modified by customAjaxUrl
|
2015-11-20 15:27:22 +00:00
|
|
|
p.ajaxObject.success = function( data, status, jqxhr ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
// Refuse to process old ajax commands that were overwritten by new ones - see #443
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( counter < p.ajaxCounter ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-11-20 15:27:22 +00:00
|
|
|
tsp.renderAjax( data, c, jqxhr );
|
|
|
|
$doc.off( 'ajaxError' + namespace );
|
|
|
|
if ( typeof p.oldAjaxSuccess === 'function' ) {
|
|
|
|
p.oldAjaxSuccess( data );
|
2014-04-18 16:04:45 +00:00
|
|
|
}
|
2015-07-23 04:29:51 +00:00
|
|
|
};
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( c.debug ) {
|
|
|
|
console.log( 'Pager: Ajax initialized', p.ajaxObject );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
2015-11-20 15:27:22 +00:00
|
|
|
$.ajax( p.ajaxObject );
|
2013-11-09 05:49:30 +00:00
|
|
|
}
|
2015-07-23 04:29:51 +00:00
|
|
|
},
|
|
|
|
|
2015-11-20 15:27:22 +00:00
|
|
|
getAjaxUrl: function( c ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
var indx, len,
|
|
|
|
p = c.pager,
|
|
|
|
wo = c.widgetOptions,
|
2015-11-20 15:27:22 +00:00
|
|
|
url = wo.pager_ajaxUrl ? wo.pager_ajaxUrl
|
2015-07-23 04:29:51 +00:00
|
|
|
// allow using '{page+1}' in the url string to switch to a non-zero based index
|
2015-11-20 15:27:22 +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"
|
2015-11-20 15:27:22 +00:00
|
|
|
.replace( /\{size\}/g, p.size ) : '',
|
2015-07-23 04:29:51 +00:00
|
|
|
sortList = c.sortList,
|
2015-11-20 15:27:22 +00:00
|
|
|
filterList = p.currentFilters || c.$table.data( 'lastSearch' ) || [],
|
|
|
|
sortCol = url.match( /\{\s*sort(?:List)?\s*:\s*(\w*)\s*\}/ ),
|
|
|
|
filterCol = url.match( /\{\s*filter(?:List)?\s*:\s*(\w*)\s*\}/ ),
|
2015-07-23 04:29:51 +00:00
|
|
|
arry = [];
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( sortCol ) {
|
|
|
|
sortCol = sortCol[ 1 ];
|
2015-07-23 04:29:51 +00:00
|
|
|
len = sortList.length;
|
2015-11-20 15:27:22 +00:00
|
|
|
for ( indx = 0; indx < len; indx++ ) {
|
2016-02-22 03:47:59 +00:00
|
|
|
arry[ arry.length ] = sortCol + '[' + sortList[ indx ][ 0 ] + ']=' + sortList[ indx ][ 1 ];
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
|
|
|
// if the arry is empty, just add the col parameter... '&{sortList:col}' becomes '&col'
|
2015-11-20 15:27:22 +00:00
|
|
|
url = url.replace( /\{\s*sort(?:List)?\s*:\s*(\w*)\s*\}/g, arry.length ? arry.join( '&' ) : sortCol );
|
2015-07-23 04:29:51 +00:00
|
|
|
arry = [];
|
2015-02-26 00:43:59 +00:00
|
|
|
}
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( filterCol ) {
|
|
|
|
filterCol = filterCol[ 1 ];
|
2015-07-23 04:29:51 +00:00
|
|
|
len = filterList.length;
|
2015-11-20 15:27:22 +00:00
|
|
|
for ( indx = 0; indx < len; indx++ ) {
|
|
|
|
if ( filterList[ indx ] ) {
|
2016-02-22 03:47:59 +00:00
|
|
|
arry[ arry.length ] = filterCol + '[' + indx + ']=' + encodeURIComponent( filterList[ indx ] );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
2013-10-18 03:59:07 +00:00
|
|
|
}
|
2015-07-23 04:29:51 +00:00
|
|
|
// if the arry is empty, just add the fcol parameter... '&{filterList:fcol}' becomes '&fcol'
|
2015-11-20 15:27:22 +00:00
|
|
|
url = url.replace( /\{\s*filter(?:List)?\s*:\s*(\w*)\s*\}/g, arry.length ? arry.join( '&' ) : filterCol );
|
2015-07-23 04:29:51 +00:00
|
|
|
p.currentFilters = filterList;
|
2015-02-26 00:43:59 +00:00
|
|
|
}
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( $.isFunction( wo.pager_customAjaxUrl ) ) {
|
|
|
|
url = wo.pager_customAjaxUrl( c.table, url );
|
2014-07-11 19:51:50 +00:00
|
|
|
}
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( c.debug ) {
|
|
|
|
console.log( 'Pager: Ajax url = ' + url );
|
2015-02-27 23:37:14 +00:00
|
|
|
}
|
2015-07-23 04:29:51 +00:00
|
|
|
return url;
|
|
|
|
},
|
|
|
|
|
2015-11-20 15:27:22 +00:00
|
|
|
renderTable: function( c, rows ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
var $tb, index, count, added,
|
2015-11-20 15:27:22 +00:00
|
|
|
table = c.table,
|
2015-07-23 04:29:51 +00:00
|
|
|
p = c.pager,
|
|
|
|
wo = c.widgetOptions,
|
|
|
|
f = c.$table.hasClass('hasFilters'),
|
|
|
|
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 );
|
2015-07-23 04:29:51 +00:00
|
|
|
if ( l < 1 ) {
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( c.debug ) {
|
|
|
|
console.warn( 'Pager: >> No rows for pager to render' );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
|
|
|
// empty table, abort!
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ( p.page >= p.totalPages ) {
|
|
|
|
// lets not render the table more than once
|
2015-11-20 15:27:22 +00:00
|
|
|
return tsp.moveToLastPage( c, p );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
|
|
|
p.cacheIndex = [];
|
|
|
|
p.isDisabled = false; // needed because sorting will change the page and re-enable the pager
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( p.initialized ) {
|
|
|
|
if ( c.debug ) {
|
|
|
|
console.log( 'Pager: Triggering pagerChange' );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
2015-12-02 01:38:56 +00:00
|
|
|
c.$table.triggerHandler( 'pagerChange', c );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
2015-10-27 22:31:50 +00:00
|
|
|
if ( !wo.pager_removeRows ) {
|
2015-11-20 15:27:22 +00:00
|
|
|
tsp.hideRows( c );
|
2015-07-23 04:29:51 +00:00
|
|
|
} else {
|
2015-11-20 15:27:22 +00:00
|
|
|
ts.clearTableBody( table );
|
|
|
|
$tb = ts.processTbody( table, c.$tbodies.eq(0), true );
|
2015-07-23 04:29:51 +00:00
|
|
|
// not filtered, start from the calculated starting point (s)
|
|
|
|
// if filtered, start from zero
|
|
|
|
index = f ? 0 : s;
|
|
|
|
count = f ? 0 : s;
|
|
|
|
added = 0;
|
2015-11-20 15:27:22 +00:00
|
|
|
while ( added < e && index < rows.length ) {
|
2016-06-28 09:28:35 +00:00
|
|
|
if ( !f || !p.regexFiltered.test( rows[ index ][ 0 ].className ) ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
count++;
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( count > s && added <= e ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
added++;
|
2016-02-22 03:47:59 +00:00
|
|
|
p.cacheIndex[ p.cacheIndex.length ] = index;
|
2015-11-20 15:27:22 +00:00
|
|
|
$tb.append( rows[ index ] );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
2014-04-18 16:36:19 +00:00
|
|
|
}
|
2015-07-23 04:29:51 +00:00
|
|
|
index++;
|
2014-04-18 16:36:19 +00:00
|
|
|
}
|
2015-11-20 15:27:22 +00:00
|
|
|
ts.processTbody( table, $tb, false );
|
2013-10-18 03:59:07 +00:00
|
|
|
}
|
2015-11-20 15:27:22 +00:00
|
|
|
tsp.updatePageDisplay( c );
|
2013-10-18 03:59:07 +00:00
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
wo.pager_startPage = p.page;
|
|
|
|
wo.pager_size = p.size;
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( table.isUpdating ) {
|
|
|
|
if ( c.debug ) {
|
|
|
|
console.log( 'Pager: Triggering updateComplete' );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
2015-12-02 01:38:56 +00:00
|
|
|
c.$table.triggerHandler( 'updateComplete', [ table, true ] );
|
2015-02-27 23:37:14 +00:00
|
|
|
}
|
2013-10-18 03:59:07 +00:00
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
},
|
2013-10-18 03:59:07 +00:00
|
|
|
|
2015-11-20 15:27:22 +00:00
|
|
|
showAllRows: function( c ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
var index, $controls, len,
|
2015-11-20 15:27:22 +00:00
|
|
|
table = c.table,
|
2015-07-23 04:29:51 +00:00
|
|
|
p = c.pager,
|
|
|
|
wo = c.widgetOptions;
|
|
|
|
if ( p.ajax ) {
|
2015-11-20 15:27:22 +00:00
|
|
|
tsp.pagerArrows( c, true );
|
2015-07-23 04:29:51 +00:00
|
|
|
} else {
|
2015-11-20 15:27:22 +00:00
|
|
|
$.data( table, 'pagerLastPage', p.page );
|
|
|
|
$.data( table, 'pagerLastSize', p.size );
|
2015-07-23 04:29:51 +00:00
|
|
|
p.page = 0;
|
2017-04-02 08:40:10 +00:00
|
|
|
p.size = p.totalPages;
|
2015-07-23 04:29:51 +00:00
|
|
|
p.totalPages = 1;
|
|
|
|
c.$table
|
2015-11-20 15:27:22 +00:00
|
|
|
.addClass( 'pagerDisabled' )
|
|
|
|
.removeAttr( 'aria-describedby' )
|
|
|
|
.find( 'tr.pagerSavedHeightSpacer' )
|
|
|
|
.remove();
|
|
|
|
tsp.renderTable( c, c.rowsCopy );
|
2015-09-25 17:17:38 +00:00
|
|
|
p.isDisabled = true;
|
2015-10-22 21:41:34 +00:00
|
|
|
ts.applyWidget( table );
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( c.debug ) {
|
|
|
|
console.log( 'Pager: Disabled' );
|
2014-07-11 19:51:50 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-23 04:29:51 +00:00
|
|
|
// disable size selector
|
2016-12-16 23:13:02 +00:00
|
|
|
$controls = p.$container.find(
|
|
|
|
wo.pager_selectors.pageSize + ',' +
|
|
|
|
wo.pager_selectors.gotoPage + ',' +
|
|
|
|
'.ts-startRow, .ts-page'
|
|
|
|
);
|
2015-07-23 04:29:51 +00:00
|
|
|
len = $controls.length;
|
|
|
|
for ( index = 0; index < len; index++ ) {
|
|
|
|
$controls.eq( index )
|
2016-11-26 15:57:00 +00:00
|
|
|
.prop( 'aria-disabled', 'true' )
|
2015-11-20 15:27:22 +00:00
|
|
|
.addClass( wo.pager_css.disabled )[ 0 ].disabled = true;
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
|
|
|
},
|
2014-07-11 19:51:50 +00:00
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
// updateCache if delayInit: true
|
|
|
|
// this is normally done by 'appendToTable' function in the tablesorter core AFTER a sort
|
2015-11-20 15:27:22 +00:00
|
|
|
updateCache: function( c ) {
|
|
|
|
var p = c.pager;
|
2015-10-22 21:41:34 +00:00
|
|
|
// tablesorter core updateCache (not pager)
|
2015-11-20 15:27:22 +00:00
|
|
|
ts.updateCache( c, function() {
|
|
|
|
if ( !$.isEmptyObject( c.cache ) ) {
|
|
|
|
var index,
|
2015-07-23 04:29:51 +00:00
|
|
|
rows = [],
|
2015-11-20 15:27:22 +00:00
|
|
|
normalized = c.cache[ 0 ].normalized;
|
|
|
|
p.totalRows = normalized.length;
|
|
|
|
for ( index = 0; index < p.totalRows; index++ ) {
|
2016-02-22 03:47:59 +00:00
|
|
|
rows[ rows.length ] = normalized[ index ][ c.columns ].$row;
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
|
|
|
c.rowsCopy = rows;
|
2015-11-20 15:27:22 +00:00
|
|
|
tsp.moveToPage( c, p, true );
|
2015-07-23 04:29:51 +00:00
|
|
|
// clear out last search to force an update
|
|
|
|
p.last.currentFilters = [ ' ' ];
|
|
|
|
}
|
2015-10-22 21:41:34 +00:00
|
|
|
});
|
2015-07-23 04:29:51 +00:00
|
|
|
},
|
|
|
|
|
2015-11-20 15:27:22 +00:00
|
|
|
moveToPage: function( c, p, pageMoved ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
if ( p.isDisabled ) { return; }
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( pageMoved !== false && p.initialized && $.isEmptyObject( c.cache ) ) {
|
|
|
|
return tsp.updateCache( c );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
2016-01-24 16:10:58 +00:00
|
|
|
var tmp,
|
|
|
|
table = c.table,
|
2015-07-23 04:29:51 +00:00
|
|
|
wo = c.widgetOptions,
|
|
|
|
l = p.last;
|
|
|
|
|
|
|
|
// abort page move if the table has filters and has not been initialized
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( p.ajax && !wo.filter_initialized && ts.hasWidget( table, 'filter' ) ) { return; }
|
2015-07-23 04:29:51 +00:00
|
|
|
|
2015-11-19 00:58:50 +00:00
|
|
|
tsp.parsePageNumber( c, p );
|
|
|
|
tsp.calcFilters( c );
|
2015-07-23 04:29:51 +00:00
|
|
|
|
|
|
|
// fixes issue where one current filter is [] and the other is [ '', '', '' ],
|
|
|
|
// making the next if comparison think the filters as different. Fixes #202.
|
2015-11-20 15:27:22 +00:00
|
|
|
l.currentFilters = ( l.currentFilters || [] ).join( '' ) === '' ? [] : l.currentFilters;
|
|
|
|
p.currentFilters = ( p.currentFilters || [] ).join( '' ) === '' ? [] : p.currentFilters;
|
2015-07-23 04:29:51 +00:00
|
|
|
// 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 &&
|
2015-11-20 15:27:22 +00:00
|
|
|
( l.currentFilters || [] ).join( ',' ) === ( p.currentFilters || [] ).join( ',' ) &&
|
2015-07-23 04:29:51 +00:00
|
|
|
// check for ajax url changes see #730
|
2015-11-20 15:27:22 +00:00
|
|
|
( l.ajaxUrl || '' ) === ( p.ajaxObject.url || '' ) &&
|
2015-07-23 04:29:51 +00:00
|
|
|
// & ajax url option changes (dynamically add/remove/rename sort & filter parameters)
|
2015-11-20 15:27:22 +00:00
|
|
|
( l.optAjaxUrl || '' ) === ( wo.pager_ajaxUrl || '' ) &&
|
|
|
|
l.sortList === ( c.sortList || [] ).join( ',' ) ) {
|
2014-02-22 17:17:26 +00:00
|
|
|
return;
|
2014-02-02 04:06:01 +00:00
|
|
|
}
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( c.debug ) {
|
|
|
|
console.log( 'Pager: Changing to page ' + p.page );
|
2015-02-27 23:37:14 +00:00
|
|
|
}
|
2015-07-23 04:29:51 +00:00
|
|
|
p.last = {
|
2015-11-20 15:27:22 +00:00
|
|
|
page: p.page,
|
|
|
|
size: p.size,
|
2015-07-23 04:29:51 +00:00
|
|
|
// fixes #408; modify sortList otherwise it auto-updates
|
2015-11-20 15:27:22 +00:00
|
|
|
sortList: ( c.sortList || [] ).join( ',' ),
|
|
|
|
totalRows: p.totalRows,
|
|
|
|
currentFilters: p.currentFilters || [],
|
|
|
|
ajaxUrl: p.ajaxObject.url || '',
|
|
|
|
optAjaxUrl: wo.pager_ajaxUrl
|
2015-07-23 04:29:51 +00:00
|
|
|
};
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( p.ajax ) {
|
2016-01-24 16:10:58 +00:00
|
|
|
if ( !wo.pager_processAjaxOnInit && !$.isEmptyObject(wo.pager_initialRows) ) {
|
|
|
|
wo.pager_processAjaxOnInit = true;
|
|
|
|
tmp = wo.pager_initialRows;
|
|
|
|
p.totalRows = typeof tmp.total !== 'undefined' ? tmp.total :
|
|
|
|
( c.debug ? console.error('Pager: no initial total page set!') || 0 : 0 );
|
|
|
|
p.filteredRows = typeof tmp.filtered !== 'undefined' ? tmp.filtered :
|
|
|
|
( c.debug ? console.error('Pager: no initial filtered page set!') || 0 : 0 );
|
|
|
|
tsp.updatePageDisplay( c, false );
|
2016-07-09 23:34:17 +00:00
|
|
|
} else if (p.initialized) {
|
2016-01-24 16:10:58 +00:00
|
|
|
tsp.getAjax( c );
|
|
|
|
}
|
2015-11-20 15:27:22 +00:00
|
|
|
} else if ( !p.ajax ) {
|
|
|
|
tsp.renderTable( c, c.rowsCopy );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
2015-11-20 15:27:22 +00:00
|
|
|
$.data( table, 'pagerLastPage', p.page );
|
|
|
|
if ( p.initialized && pageMoved !== false ) {
|
|
|
|
if ( c.debug ) {
|
|
|
|
console.log( 'Pager: Triggering pageMoved' );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
2015-12-02 01:38:56 +00:00
|
|
|
c.$table.triggerHandler( 'pageMoved', c );
|
2015-10-22 21:41:34 +00:00
|
|
|
ts.applyWidget( table );
|
2015-11-20 15:27:22 +00:00
|
|
|
if ( !p.ajax && table.isUpdating ) {
|
|
|
|
if ( c.debug ) {
|
|
|
|
console.log( 'Pager: Triggering updateComplete' );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
2015-12-02 01:38:56 +00:00
|
|
|
c.$table.triggerHandler( 'updateComplete', [ table, true ] );
|
2015-02-27 23:37:14 +00:00
|
|
|
}
|
2014-03-07 02:28:47 +00:00
|
|
|
}
|
2015-07-23 04:29:51 +00:00
|
|
|
},
|
|
|
|
|
2015-11-19 15:41:35 +00:00
|
|
|
getTotalPages: function( c, p ) {
|
2017-04-02 08:40:10 +00:00
|
|
|
return ts.hasWidget( c.table, 'filter' ) ?
|
|
|
|
Math.min( p.totalPages, p.filteredPages ) :
|
|
|
|
p.totalPages;
|
2015-10-26 01:55:48 +00:00
|
|
|
},
|
|
|
|
|
2015-11-19 00:58:50 +00:00
|
|
|
parsePageNumber: function( c, p ) {
|
2015-11-19 15:41:35 +00:00
|
|
|
var min = tsp.getTotalPages( c, p ) - 1;
|
2015-10-30 20:25:38 +00:00
|
|
|
p.page = parseInt( p.page, 10 );
|
|
|
|
if ( p.page < 0 || isNaN( p.page ) ) { p.page = 0; }
|
2015-11-20 15:30:21 +00:00
|
|
|
if ( p.page > min && min >= 0 ) { p.page = min; }
|
2015-10-30 20:25:38 +00:00
|
|
|
return p.page;
|
|
|
|
},
|
|
|
|
|
2017-04-02 08:40:10 +00:00
|
|
|
// set to either set or get value
|
|
|
|
parsePageSize: function( c, size, mode ) {
|
|
|
|
var p = c.pager,
|
|
|
|
wo = c.widgetOptions,
|
|
|
|
s = parseInt( size, 10 ) || p.size || wo.pager_size || 10;
|
|
|
|
if (p.initialized && (/all/i.test( s + ' ' + size ) || s === p.totalRows)) {
|
|
|
|
// Fixing #1364 & #1366
|
|
|
|
return p.$container.find( wo.pager_selectors.pageSize + ' option[value="all"]').length ?
|
|
|
|
'all' : p.totalRows;
|
|
|
|
}
|
|
|
|
// "get" to set `p.size` or "set" to set `pageSize.val()`
|
|
|
|
return mode === 'get' ? s : p.size;
|
|
|
|
},
|
|
|
|
|
2015-11-20 15:27:22 +00:00
|
|
|
setPageSize: function( c, size ) {
|
2015-10-30 21:13:36 +00:00
|
|
|
var p = c.pager,
|
|
|
|
table = c.table;
|
2017-04-02 08:40:10 +00:00
|
|
|
// "all" size is only returned if an "all" option exists - fixes #1366
|
2015-10-30 21:13:36 +00:00
|
|
|
p.size = tsp.parsePageSize( c, size, 'get' );
|
2016-12-16 23:13:02 +00:00
|
|
|
p.$container
|
|
|
|
.find( c.widgetOptions.pager_selectors.pageSize )
|
2017-04-02 08:40:10 +00:00
|
|
|
.val( p.size );
|
2015-11-20 15:27:22 +00:00
|
|
|
$.data( table, 'pagerLastPage', tsp.parsePageNumber( c, p ) );
|
|
|
|
$.data( table, 'pagerLastSize', p.size );
|
2016-05-01 20:25:01 +00:00
|
|
|
p.totalPages = p.size === 'all' ? 1 : Math.ceil( p.totalRows / p.size );
|
|
|
|
p.filteredPages = p.size === 'all' ? 1 : Math.ceil( p.filteredRows / p.size );
|
2015-07-23 04:29:51 +00:00
|
|
|
},
|
2013-10-18 03:59:07 +00:00
|
|
|
|
2015-11-20 15:27:22 +00:00
|
|
|
moveToFirstPage: function( c, p ) {
|
2013-10-18 03:59:07 +00:00
|
|
|
p.page = 0;
|
2015-11-20 15:27:22 +00:00
|
|
|
tsp.moveToPage( c, p, true );
|
2015-07-23 04:29:51 +00:00
|
|
|
},
|
|
|
|
|
2015-11-20 15:27:22 +00:00
|
|
|
moveToLastPage: function( c, p ) {
|
|
|
|
p.page = tsp.getTotalPages( c, p ) - 1;
|
|
|
|
tsp.moveToPage( c, p, true );
|
2015-07-23 04:29:51 +00:00
|
|
|
},
|
|
|
|
|
2015-11-20 15:27:22 +00:00
|
|
|
moveToNextPage: function( c, p ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
p.page++;
|
2015-11-20 15:27:22 +00:00
|
|
|
var last = tsp.getTotalPages( c, p ) - 1;
|
2015-11-19 15:41:35 +00:00
|
|
|
if ( p.page >= last ) {
|
|
|
|
p.page = last;
|
2013-11-09 05:49:30 +00:00
|
|
|
}
|
2015-11-20 15:27:22 +00:00
|
|
|
tsp.moveToPage( c, p, true );
|
2015-07-23 04:29:51 +00:00
|
|
|
},
|
|
|
|
|
2015-11-20 15:27:22 +00:00
|
|
|
moveToPrevPage: function( c, p ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
p.page--;
|
|
|
|
if ( p.page <= 0 ) {
|
|
|
|
p.page = 0;
|
|
|
|
}
|
2015-11-20 15:27:22 +00:00
|
|
|
tsp.moveToPage( c, p, true );
|
2015-07-23 04:29:51 +00:00
|
|
|
},
|
|
|
|
|
2015-11-20 15:27:22 +00:00
|
|
|
destroyPager: function( c, refreshing ) {
|
|
|
|
var table = c.table,
|
|
|
|
p = c.pager,
|
2016-02-15 18:01:19 +00:00
|
|
|
s = c.widgetOptions.pager_selectors || {},
|
2015-07-30 22:37:59 +00:00
|
|
|
ctrls = [ s.first, s.prev, s.next, s.last, s.gotoPage, s.pageSize ].join( ',' ),
|
2015-07-23 04:29:51 +00:00
|
|
|
namespace = c.namespace + 'pager';
|
2016-02-15 18:01:19 +00:00
|
|
|
// check pager object in case two successive pager destroys are triggered
|
|
|
|
// e.g. "destroyPager" then "removeWidget" - see #1155
|
|
|
|
if ( p ) {
|
|
|
|
p.initialized = false;
|
|
|
|
c.$table.off( namespace );
|
|
|
|
p.$container
|
|
|
|
// hide pager
|
|
|
|
.hide()
|
|
|
|
// unbind pager controls
|
|
|
|
.find( ctrls )
|
|
|
|
.off( namespace );
|
|
|
|
if ( refreshing ) { return; }
|
|
|
|
c.appender = null; // remove pager appender function
|
|
|
|
tsp.showAllRows( c );
|
|
|
|
if ( ts.storage ) {
|
|
|
|
ts.storage( table, c.widgetOptions.pager_storageKey, '' );
|
|
|
|
}
|
|
|
|
p.$container = null;
|
|
|
|
c.pager = null;
|
|
|
|
c.rowsCopy = null;
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-11-20 15:27:22 +00:00
|
|
|
enablePager: function( c, triggered ) {
|
2016-12-16 23:13:02 +00:00
|
|
|
var info, size,
|
2015-11-20 15:27:22 +00:00
|
|
|
table = c.table,
|
2016-12-16 23:13:02 +00:00
|
|
|
p = c.pager,
|
|
|
|
wo = c.widgetOptions,
|
|
|
|
$el = p.$container.find( wo.pager_selectors.pageSize );
|
2015-07-23 04:29:51 +00:00
|
|
|
p.isDisabled = false;
|
2015-11-20 15:27:22 +00:00
|
|
|
p.page = $.data( table, 'pagerLastPage' ) || p.page || 0;
|
2016-12-16 23:13:02 +00:00
|
|
|
size = $el.find('option[selected]' ).val();
|
2015-11-20 15:27:22 +00:00
|
|
|
p.size = $.data( table, 'pagerLastSize' ) || tsp.parsePageSize( c, size, 'get' );
|
2017-04-02 08:40:10 +00:00
|
|
|
tsp.setPageSize( c, p.size ); // set page size
|
2016-05-01 20:25:01 +00:00
|
|
|
p.totalPages = p.size === 'all' ? 1 : Math.ceil( tsp.getTotalPages( c, p ) / p.size );
|
2015-11-20 15:27:22 +00:00
|
|
|
c.$table.removeClass( 'pagerDisabled' );
|
2015-07-23 04:29:51 +00:00
|
|
|
// if table id exists, include page display with aria info
|
2016-09-23 02:09:18 +00:00
|
|
|
if ( table.id && !c.$table.attr( 'aria-describedby' ) ) {
|
2016-12-16 23:13:02 +00:00
|
|
|
$el = p.$container.find( wo.pager_selectors.pageDisplay );
|
2016-09-23 02:09:18 +00:00
|
|
|
info = $el.attr( 'id' );
|
|
|
|
if ( !info ) {
|
|
|
|
// only add pageDisplay id if it doesn't exist - see #1288
|
|
|
|
info = table.id + '_pager_info';
|
|
|
|
$el.attr( 'id', info );
|
|
|
|
}
|
2015-11-20 15:27:22 +00:00
|
|
|
c.$table.attr( 'aria-describedby', info );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
2015-11-20 15:27:22 +00:00
|
|
|
tsp.changeHeight( c );
|
2015-07-23 04:29:51 +00:00
|
|
|
if ( triggered ) {
|
2015-10-22 21:41:34 +00:00
|
|
|
// tablesorter core update table
|
|
|
|
ts.update( c );
|
2015-11-20 15:27:22 +00:00
|
|
|
tsp.setPageSize( c, p.size );
|
2017-04-02 08:40:10 +00:00
|
|
|
tsp.moveToPage( c, p, true );
|
2015-11-20 15:27:22 +00:00
|
|
|
tsp.hideRowsSetup( c );
|
|
|
|
if ( c.debug ) {
|
|
|
|
console.log( 'Pager: Enabled' );
|
2015-07-23 04:29:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-11-20 15:27:22 +00:00
|
|
|
appender: function( table, rows ) {
|
2015-07-23 04:29:51 +00:00
|
|
|
var c = table.config,
|
|
|
|
wo = c.widgetOptions,
|
|
|
|
p = c.pager;
|
|
|
|
if ( !p.ajax ) {
|
|
|
|
c.rowsCopy = rows;
|
2015-11-20 15:27:22 +00:00
|
|
|
p.totalRows = wo.pager_countChildRows ? c.$tbodies.eq( 0 ).children( 'tr' ).length : rows.length;
|
|
|
|
p.size = $.data( table, 'pagerLastSize' ) || p.size || wo.pager_size || p.setSize || 10;
|
2016-05-01 20:25:01 +00:00
|
|
|
p.totalPages = p.size === 'all' ? 1 : Math.ceil( p.totalRows / p.size );
|
2015-11-20 15:27:22 +00:00
|
|
|
tsp.moveToPage( c, p );
|
2015-07-23 04:29:51 +00:00
|
|
|
// update display here in case all rows are removed
|
2015-11-20 15:27:22 +00:00
|
|
|
tsp.updatePageDisplay( c, false );
|
2014-02-05 12:10:55 +00:00
|
|
|
} else {
|
2015-11-20 15:27:22 +00:00
|
|
|
tsp.moveToPage( c, p, true );
|
2015-07-23 04:29:51 +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,
|
2015-07-23 04:29:51 +00:00
|
|
|
$table = $( table ),
|
2015-11-20 15:27:22 +00:00
|
|
|
c = $table[ 0 ].config,
|
2015-08-15 15:56:42 +00:00
|
|
|
wo = c && c.widgetOptions,
|
2015-08-19 21:33:32 +00:00
|
|
|
errorRow = c.pager && c.pager.cssErrorRow ||
|
|
|
|
wo && wo.pager_css && wo.pager_css.errorRow ||
|
|
|
|
'tablesorter-errorRow',
|
2015-08-15 15:56:42 +00:00
|
|
|
typ = typeof xhr,
|
|
|
|
valid = true,
|
|
|
|
message = '',
|
2015-11-20 15:27:22 +00:00
|
|
|
removeRow = function() {
|
2015-08-15 15:56:42 +00:00
|
|
|
c.$table.find( 'thead' ).find( '.' + errorRow ).remove();
|
|
|
|
};
|
|
|
|
|
|
|
|
if ( !$table.length ) {
|
2015-11-20 15:27:22 +00:00
|
|
|
console.error( 'tablesorter showError: no table parameter passed' );
|
2015-08-15 15:56:42 +00:00
|
|
|
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 =
|
|
|
|
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-08-15 15:56:42 +00:00
|
|
|
|
2015-08-19 21:33:32 +00:00
|
|
|
// allow message to include entire row HTML!
|
2015-11-20 15:27:22 +00:00
|
|
|
$row = ( /tr\>/.test( message ) ?
|
|
|
|
$( message ) :
|
|
|
|
$( '<tr><td colspan="' + c.columns + '">' + message + '</td></tr>' ) )
|
2015-08-15 15:56:42 +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' ) )
|
2015-11-20 15:27:22 +00:00
|
|
|
.addClass( errorRow + ' ' + c.selectorRemove.slice( 1 ) )
|
2015-08-15 15:56:42 +00:00
|
|
|
.attr({
|
2015-11-20 15:27:22 +00:00
|
|
|
role: 'alert',
|
|
|
|
'aria-live': 'assertive'
|
2015-08-15 15:56:42 +00:00
|
|
|
});
|
|
|
|
|
2015-07-23 04:29:51 +00:00
|
|
|
};
|
2014-02-05 12:10:55 +00:00
|
|
|
|
2013-10-18 03:59:07 +00:00
|
|
|
})(jQuery);
|