new pager events - issue #153

Added "pagerInitialized" and "pageMoved" thanks to ViViDboarder
This commit is contained in:
Mottie 2012-10-15 16:43:09 -05:00
parent a8e13d6c17
commit 4f1aa02a93
6 changed files with 3721 additions and 3642 deletions

Binary file not shown.

View File

@ -1,485 +1,497 @@
/*! /*!
* tablesorter pager plugin * tablesorter pager plugin
* updated 10/13/2012 * updated 10/15/2012
*/ */
/*jshint browser:true, jquery:true */ /*jshint browser:true, jquery:true */
;(function($) { ;(function($) {
"use strict"; "use strict";
$.extend({tablesorterPager: new function() { $.extend({tablesorterPager: new function() {
this.defaults = { this.defaults = {
// target the pager markup // target the pager markup
container: null, container: null,
// use this format: "http:/mydatabase.com?page={page}&size={size}" // use this format: "http:/mydatabase.com?page={page}&size={size}"
// where {page} is replaced by the page number and {size} is replaced by the number of records to show // where {page} is replaced by the page number and {size} is replaced by the number of records to show
ajaxUrl: null, ajaxUrl: null,
// process ajax so that the following information is returned: // process ajax so that the following information is returned:
// [ total_rows (number), rows (array of arrays), headers (array; optional) ] // [ total_rows (number), rows (array of arrays), headers (array; optional) ]
// example: // example:
// [ // [
// 100, // total rows // 100, // total rows
// [ // [
// [ "row1cell1", "row1cell2", ... "row1cellN" ], // [ "row1cell1", "row1cell2", ... "row1cellN" ],
// [ "row2cell1", "row2cell2", ... "row2cellN" ], // [ "row2cell1", "row2cell2", ... "row2cellN" ],
// ... // ...
// [ "rowNcell1", "rowNcell2", ... "rowNcellN" ] // [ "rowNcell1", "rowNcell2", ... "rowNcellN" ]
// ], // ],
// [ "header1", "header2", ... "headerN" ] // optional // [ "header1", "header2", ... "headerN" ] // optional
// ] // ]
ajaxProcessing: function(ajax){ return [ 0, [], null ]; }, ajaxProcessing: function(ajax){ return [ 0, [], null ]; },
// output default: '{page}/{totalPages}' // output default: '{page}/{totalPages}'
// possible variables: {page}, {totalPages}, {filteredPages}, {startRow}, {endRow}, {filteredRows} and {totalRows} // possible variables: {page}, {totalPages}, {filteredPages}, {startRow}, {endRow}, {filteredRows} and {totalRows}
output: '{startRow} to {endRow} of {totalRows} rows', // '{page}/{totalPages}' output: '{startRow} to {endRow} of {totalRows} rows', // '{page}/{totalPages}'
// apply disabled classname to the pager arrows when the rows at either extreme is visible // apply disabled classname to the pager arrows when the rows at either extreme is visible
updateArrows: true, updateArrows: true,
// starting page of the pager (zero based index) // starting page of the pager (zero based index)
page: 0, page: 0,
// Number of visible rows // Number of visible rows
size: 10, size: 10,
// if true, the table will remain the same height no matter how many records are displayed. The space is made up by an empty // 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 // table row set to a height to compensate; default is false
fixedHeight: false, fixedHeight: false,
// remove rows from the table to speed up the sort of large tables. // 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. // 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 removeRows: false, // removing rows in larger tables speeds up the sort
// css class names of pager arrows // css class names of pager arrows
cssFirst: '.first', // go to first page arrow cssFirst: '.first', // go to first page arrow
cssPrev: '.prev', // previous page arrow cssPrev: '.prev', // previous page arrow
cssNext: '.next', // next page arrow cssNext: '.next', // next page arrow
cssLast: '.last', // go to last page arrow cssLast: '.last', // go to last page arrow
cssGoto: '.gotoPage', // go to page selector - select dropdown that sets the current page cssGoto: '.gotoPage', // go to page selector - select dropdown that sets the current page
cssPageDisplay: '.pagedisplay', // location of where the "output" is displayed cssPageDisplay: '.pagedisplay', // location of where the "output" is displayed
cssPageSize: '.pagesize', // page size selector - select dropdown that sets the "size" option cssPageSize: '.pagesize', // page size selector - select dropdown that sets the "size" option
// class added to arrows when at the extremes (i.e. prev/first arrows are "disabled" when on the first page) // 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 cssDisabled: 'disabled', // Note there is no period "." in front of this class name
// stuff not set by the user // stuff not set by the user
totalRows: 0, totalRows: 0,
totalPages: 0, totalPages: 0,
filteredRows: 0, filteredRows: 0,
filteredPages : 0 filteredPages : 0
}; };
var $this = this, var $this = this,
// hide arrows at extremes // hide arrows at extremes
pagerArrows = function(c, disable) { pagerArrows = function(c, disable) {
var a = 'addClass', var a = 'addClass',
r = 'removeClass', r = 'removeClass',
d = c.cssDisabled, d = c.cssDisabled,
dis = !!disable, dis = !!disable,
// tr = Math.min( c.totalRows, c.filteredRows ), // tr = Math.min( c.totalRows, c.filteredRows ),
tp = Math.min( c.totalPages, c.filteredPages ); tp = Math.min( c.totalPages, c.filteredPages );
if ( c.updateArrows ) { if ( c.updateArrows ) {
$(c.cssFirst + ',' + c.cssPrev, c.container)[ ( dis || c.page === 0 ) ? a : r ](d); $(c.cssFirst + ',' + c.cssPrev, c.container)[ ( dis || c.page === 0 ) ? a : r ](d);
$(c.cssNext + ',' + c.cssLast, c.container)[ ( dis || c.page === tp - 1 ) ? a : r ](d); $(c.cssNext + ',' + c.cssLast, c.container)[ ( dis || c.page === tp - 1 ) ? a : r ](d);
} }
}, },
updatePageDisplay = function(table, c) { updatePageDisplay = function(table, c) {
var i, p, s, t, out, f = $(table).hasClass('hasFilters'); var i, p, s, t, out, f = $(table).hasClass('hasFilters');
c.filteredRows = (f) ? $(table).find('tbody tr:not(.filtered)').length : c.totalRows; c.filteredRows = (f) ? $(table).find('tbody tr:not(.filtered)').length : c.totalRows;
c.filteredPages = (f) ? Math.ceil( c.filteredRows / c.size ) : c.totalPages; c.filteredPages = (f) ? Math.ceil( c.filteredRows / c.size ) : c.totalPages;
if ( Math.min( c.totalPages, c.filteredPages ) > 0 ) { if ( Math.min( c.totalPages, c.filteredPages ) > 0 ) {
t = (c.size * c.page > c.filteredRows); t = (c.size * c.page > c.filteredRows);
c.startRow = (t) ? 1 : ( c.size * c.page ) + 1; c.startRow = (t) ? 1 : ( c.size * c.page ) + 1;
c.page = (t) ? 0 : c.page; c.page = (t) ? 0 : c.page;
c.endRow = Math.min( c.filteredRows, c.totalRows, c.size * ( c.page + 1 ) ); c.endRow = Math.min( c.filteredRows, c.totalRows, c.size * ( c.page + 1 ) );
out = $(c.cssPageDisplay, c.container); out = $(c.cssPageDisplay, c.container);
// form the output string // form the output string
s = c.output.replace(/\{(page|filteredRows|filteredPages|totalPages|startRow|endRow|totalRows)\}/gi, function(m){ s = c.output.replace(/\{(page|filteredRows|filteredPages|totalPages|startRow|endRow|totalRows)\}/gi, function(m){
return { return {
'{page}' : c.page + 1, '{page}' : c.page + 1,
'{filteredRows}' : c.filteredRows, '{filteredRows}' : c.filteredRows,
'{filteredPages}' : c.filteredPages, '{filteredPages}' : c.filteredPages,
'{totalPages}' : c.totalPages, '{totalPages}' : c.totalPages,
'{startRow}' : c.startRow, '{startRow}' : c.startRow,
'{endRow}' : c.endRow, '{endRow}' : c.endRow,
'{totalRows}' : c.totalRows '{totalRows}' : c.totalRows
}[m]; }[m];
}); });
if (out[0]) { if (out[0]) {
out[ (out[0].tagName === 'INPUT') ? 'val' : 'html' ](s); out[ (out[0].tagName === 'INPUT') ? 'val' : 'html' ](s);
if ( $(c.cssGoto, c.container).length ) { if ( $(c.cssGoto, c.container).length ) {
t = ''; t = '';
p = Math.min( c.totalPages, c.filteredPages ); p = Math.min( c.totalPages, c.filteredPages );
for ( i = 1; i <= p; i++ ) { for ( i = 1; i <= p; i++ ) {
t += '<option>' + i + '</option>'; t += '<option>' + i + '</option>';
} }
$(c.cssGoto, c.container).html(t).val(c.page + 1); $(c.cssGoto, c.container).html(t).val(c.page + 1);
} }
} }
} }
pagerArrows(c); pagerArrows(c);
$(table).trigger('pagerComplete', c); if (c.initialized) { $(table).trigger('pagerComplete', c); }
}, },
fixHeight = function(table, c) { fixHeight = function(table, c) {
var d, h, $b = $(table.tBodies[0]); var d, h, $b = $(table.tBodies[0]);
if (c.fixedHeight) { if (c.fixedHeight) {
$b.find('tr.pagerSavedHeightSpacer').remove(); $b.find('tr.pagerSavedHeightSpacer').remove();
h = $.data(table, 'pagerSavedHeight'); h = $.data(table, 'pagerSavedHeight');
if (h) { if (h) {
d = h - $b.height(); d = h - $b.height();
if ( d > 5 && $.data(table, 'pagerLastSize') === c.size && $b.find('tr:visible').length < c.size ) { if ( d > 5 && $.data(table, 'pagerLastSize') === c.size && $b.find('tr:visible').length < c.size ) {
$b.append('<tr class="pagerSavedHeightSpacer remove-me" style="height:' + d + 'px;"></tr>'); $b.append('<tr class="pagerSavedHeightSpacer remove-me" style="height:' + d + 'px;"></tr>');
} }
} }
} }
}, },
changeHeight = function(table, c) { changeHeight = function(table, c) {
var $b = $(table.tBodies[0]); var $b = $(table.tBodies[0]);
$b.find('tr.pagerSavedHeightSpacer').remove(); $b.find('tr.pagerSavedHeightSpacer').remove();
$.data(table, 'pagerSavedHeight', $b.height()); $.data(table, 'pagerSavedHeight', $b.height());
fixHeight(table, c); fixHeight(table, c);
$.data(table, 'pagerLastSize', c.size); $.data(table, 'pagerLastSize', c.size);
}, },
hideRows = function(table, c){ hideRows = function(table, c){
if (!c.ajaxUrl) { if (!c.ajaxUrl) {
var i, var i,
rows = $('tr:not(.' + table.config.cssChildRow + ')', table.tBodies), rows = $('tr:not(.' + table.config.cssChildRow + ')', table.tBodies),
l = rows.length, l = rows.length,
s = ( c.page * c.size ), s = ( c.page * c.size ),
e = s + c.size, e = s + c.size,
j = 0; // size counter j = 0; // size counter
for ( i = 0; i < l; i++ ){ for ( i = 0; i < l; i++ ){
if (!/filtered/.test(rows[i].className)) { if (!/filtered/.test(rows[i].className)) {
rows[i].style.display = ( j >= s && j < e ) ? '' : 'none'; rows[i].style.display = ( j >= s && j < e ) ? '' : 'none';
j++; j++;
} }
} }
} }
}, },
hideRowsSetup = function(table, c){ hideRowsSetup = function(table, c){
c.size = parseInt( $(c.cssPageSize, c.container).val(), 10 ) || c.size; c.size = parseInt( $(c.cssPageSize, c.container).val(), 10 ) || c.size;
$.data(table, 'pagerLastSize', c.size); $.data(table, 'pagerLastSize', c.size);
pagerArrows(c); pagerArrows(c);
if ( !c.removeRows ) { if ( !c.removeRows ) {
hideRows(table, c); hideRows(table, c);
$(table).bind('sortEnd.pager filterEnd.pager', function(){ $(table).bind('sortEnd.pager filterEnd.pager', function(){
hideRows(table, c); hideRows(table, c);
}); });
} }
}, },
renderAjax = function(data, table, c, exception){ renderAjax = function(data, table, c, exception){
// process data // process data
if ( typeof(c.ajaxProcessing) === "function" ) { if ( typeof(c.ajaxProcessing) === "function" ) {
// ajaxProcessing result: [ total, rows, headers ] // ajaxProcessing result: [ total, rows, headers ]
var i, j, hsh, $f, $sh, var i, j, hsh, $f, $sh,
$t = $(table), $t = $(table),
tc = table.config, tc = table.config,
$b = $(table.tBodies).filter(':not(.' + tc.cssInfoBlock + ')'), $b = $(table.tBodies).filter(':not(.' + tc.cssInfoBlock + ')'),
hl = $t.find('thead th').length, tds = '', hl = $t.find('thead th').length, tds = '',
err = '<tr class="' + tc.selectorRemove + '"><td style="text-align: center;" colspan="' + hl + '">' + err = '<tr class="' + tc.selectorRemove + '"><td style="text-align: center;" colspan="' + hl + '">' +
(exception ? exception.message + ' (' + exception.name + ')' : 'No rows found') + '</td></tr>', (exception ? exception.message + ' (' + exception.name + ')' : 'No rows found') + '</td></tr>',
result = c.ajaxProcessing(data) || [ 0, [] ], result = c.ajaxProcessing(data) || [ 0, [] ],
d = result[1] || [], d = result[1] || [],
l = d.length, l = d.length,
th = result[2]; th = result[2];
if ( l > 0 ) { if ( l > 0 ) {
for ( i = 0; i < l; i++ ) { for ( i = 0; i < l; i++ ) {
tds += '<tr>'; tds += '<tr>';
for ( j = 0; j < d[i].length; j++ ) { for ( j = 0; j < d[i].length; j++ ) {
// build tbody cells // build tbody cells
tds += '<td>' + d[i][j] + '</td>'; tds += '<td>' + d[i][j] + '</td>';
} }
tds += '</tr>'; tds += '</tr>';
} }
} }
// only add new header text if the length matches // only add new header text if the length matches
if ( th && th.length === hl ) { if ( th && th.length === hl ) {
hsh = $t.hasClass('hasStickyHeaders'); hsh = $t.hasClass('hasStickyHeaders');
$sh = $t.find('.' + ((tc.widgetOptions && tc.widgetOptions.stickyHeaders) || 'tablesorter-stickyheader')); $sh = $t.find('.' + ((tc.widgetOptions && tc.widgetOptions.stickyHeaders) || 'tablesorter-stickyheader'));
$f = $t.find('tfoot tr:first').children(); $f = $t.find('tfoot tr:first').children();
$t.find('th.' + tc.cssHeader).each(function(j){ $t.find('th.' + tc.cssHeader).each(function(j){
var $t = $(this), tar, icn; var $t = $(this), tar, icn;
// add new test within the first span it finds, or just in the header // add new test within the first span it finds, or just in the header
if ( $t.find('.' + tc.cssIcon).length ) { if ( $t.find('.' + tc.cssIcon).length ) {
icn = $t.find('.' + tc.cssIcon).clone(true); icn = $t.find('.' + tc.cssIcon).clone(true);
$t.find('.tablesorter-header-inner').html( th[j] ).append(icn); $t.find('.tablesorter-header-inner').html( th[j] ).append(icn);
if ( hsh && $sh.length ) { if ( hsh && $sh.length ) {
icn = $sh.find('th').eq(j).find('.' + tc.cssIcon).clone(true); icn = $sh.find('th').eq(j).find('.' + tc.cssIcon).clone(true);
$sh.find('th').eq(j).find('.tablesorter-header-inner').html( th[j] ).append(icn); $sh.find('th').eq(j).find('.tablesorter-header-inner').html( th[j] ).append(icn);
} }
} else { } else {
$t.find('.tablesorter-header-inner').html( th[j] ); $t.find('.tablesorter-header-inner').html( th[j] );
$sh.find('th').eq(j).find('.tablesorter-header-inner').html( th[j] ); $sh.find('th').eq(j).find('.tablesorter-header-inner').html( th[j] );
} }
$f.eq(j).html( th[j] ); $f.eq(j).html( th[j] );
// update sticky headers // update sticky headers
if ( hsh && $sh.length ){ if ( hsh && $sh.length ){
tar = $sh.find('th').eq(j); tar = $sh.find('th').eq(j);
tar = ( tar.find('span').length ) ? tar.find('span:first') : tar; tar = ( tar.find('span').length ) ? tar.find('span:first') : tar;
tar.html( th[j] ); tar.html( th[j] );
} }
}); });
} }
if ( exception ) { if ( exception ) {
// add error row to thead instead of tbody, or clicking on the header will result in a parser error // add error row to thead instead of tbody, or clicking on the header will result in a parser error
$t.find('thead').append(err); $t.find('thead').append(err);
} else { } else {
$b.html( tds ); // add tbody $b.html( tds ); // add tbody
} }
c.temp.remove(); // remove loading icon c.temp.remove(); // remove loading icon
$t.trigger('update'); if (c.initialized) { $t.trigger('update'); }
c.totalRows = result[0] || 0; c.totalRows = result[0] || 0;
c.totalPages = Math.ceil( c.totalRows / c.size ); c.totalPages = Math.ceil( c.totalRows / c.size );
updatePageDisplay(table, c); updatePageDisplay(table, c);
fixHeight(table, c); fixHeight(table, c);
$t.trigger('pagerChange', c); if (c.initialized) { $t.trigger('pagerChange', c); }
} }
}, if (!c.initialized) {
c.initialized = true;
getAjax = function(table, c){ $(table).trigger('pagerInitialized', c);
var $t = $(table), }
url = c.ajaxUrl.replace(/\{page\}/g, c.page).replace(/\{size\}/g, c.size); },
if ( url !== '' ) {
// loading icon getAjax = function(table, c){
c.temp = $('<div/>', { var $t = $(table),
'class' : 'tablesorter-processing', url = c.ajaxUrl.replace(/\{page\}/g, c.page).replace(/\{size\}/g, c.size);
width : $t.outerWidth(true), if ( url !== '' ) {
height: $t.outerHeight(true) // loading icon
}); c.temp = $('<div/>', {
$t.before( c.temp ); 'class' : 'tablesorter-processing',
$(document).ajaxError(function(e, xhr, settings, exception) { width : $t.outerWidth(true),
renderAjax(null, table, c, exception); height: $t.outerHeight(true)
}); });
$.getJSON(url, function(data) { $t.before( c.temp );
renderAjax(data, table, c); $(document).ajaxError(function(e, xhr, settings, exception) {
}); renderAjax(null, table, c, exception);
} });
}, $.getJSON(url, function(data) {
renderAjax(data, table, c);
renderTable = function(table, rows, c) { });
var i, j, o, }
f = document.createDocumentFragment(), },
l = rows.length,
s = ( c.page * c.size ), renderTable = function(table, rows, c) {
e = ( s + c.size ); var i, j, o,
if ( l < 1 ) { return; } // empty table, abort! f = document.createDocumentFragment(),
$(table).trigger('pagerChange', c); l = rows.length,
if ( !c.removeRows ) { s = ( c.page * c.size ),
hideRows(table, c); e = ( s + c.size );
} else { if ( l < 1 ) { return; } // empty table, abort!
if ( e > rows.length ) { if (c.initialized) { $(table).trigger('pagerChange', c); }
e = rows.length; if ( !c.removeRows ) {
} hideRows(table, c);
$(table.tBodies[0]).addClass('tablesorter-hidden'); } else {
$.tablesorter.clearTableBody(table); if ( e > rows.length ) {
for ( i = s; i < e; i++ ) { e = rows.length;
o = rows[i]; }
l = o.length; $(table.tBodies[0]).addClass('tablesorter-hidden');
for ( j = 0; j < l; j++ ) { $.tablesorter.clearTableBody(table);
f.appendChild(o[j]); for ( i = s; i < e; i++ ) {
} o = rows[i];
} l = o.length;
table.tBodies[0].appendChild(f); for ( j = 0; j < l; j++ ) {
$(table.tBodies[0]).removeClass('tablesorter-hidden'); f.appendChild(o[j]);
} }
if ( c.page >= c.totalPages ) { }
moveToLastPage(table, c); table.tBodies[0].appendChild(f);
} $(table.tBodies[0]).removeClass('tablesorter-hidden');
updatePageDisplay(table, c); }
if ( !c.isDisabled ) { fixHeight(table, c); } if ( c.page >= c.totalPages ) {
$(table).trigger('applyWidgets'); moveToLastPage(table, c);
}, }
updatePageDisplay(table, c);
showAllRows = function(table, c){ if ( !c.isDisabled ) { fixHeight(table, c); }
if ( c.ajax ) { $(table).trigger('applyWidgets');
pagerArrows(c, true); },
} else {
c.isDisabled = true; showAllRows = function(table, c){
$.data(table, 'pagerLastPage', c.page); if ( c.ajax ) {
$.data(table, 'pagerLastSize', c.size); pagerArrows(c, true);
c.page = 0; } else {
c.size = c.totalRows; c.isDisabled = true;
c.totalPages = 1; $.data(table, 'pagerLastPage', c.page);
$('tr.pagerSavedHeightSpacer', table.tBodies[0]).remove(); $.data(table, 'pagerLastSize', c.size);
renderTable(table, table.config.rowsCopy, c); c.page = 0;
} c.size = c.totalRows;
// disable size selector c.totalPages = 1;
$(c.cssPageSize, c.container).addClass(c.cssDisabled)[0].disabled = true; $('tr.pagerSavedHeightSpacer', table.tBodies[0]).remove();
}, renderTable(table, table.config.rowsCopy, c);
}
moveToPage = function(table, c) { // disable size selector
if ( c.isDisabled ) { return; } $(c.cssPageSize, c.container).addClass(c.cssDisabled)[0].disabled = true;
var p = Math.min( c.totalPages, c.filteredPages ); },
if ( c.page < 0 || c.page > ( p - 1 ) ) {
c.page = 0; moveToPage = function(table, c) {
} if ( c.isDisabled ) { return; }
$.data(table, 'pagerLastPage', c.page); var p = Math.min( c.totalPages, c.filteredPages );
if ( c.ajax ) { if ( c.page < 0 || c.page > ( p - 1 ) ) {
getAjax(table, c); c.page = 0;
} else { }
renderTable(table, table.config.rowsCopy, c); $.data(table, 'pagerLastPage', c.page);
} if ( c.ajax ) {
getAjax(table, c);
$(table).trigger('pageMoved', c); } else {
}, renderTable(table, table.config.rowsCopy, c);
}
setPageSize = function(table, size, c) { if (c.initialized) { $(table).trigger('pageMoved', c); }
c.size = size; },
$.data(table, 'pagerLastPage', c.page);
$.data(table, 'pagerLastSize', c.size); setPageSize = function(table, size, c) {
c.totalPages = Math.ceil( c.totalRows / c.size ); c.size = size;
moveToPage(table, c); $.data(table, 'pagerLastPage', c.page);
}, $.data(table, 'pagerLastSize', c.size);
c.totalPages = Math.ceil( c.totalRows / c.size );
moveToFirstPage = function(table, c) { moveToPage(table, c);
c.page = 0; },
moveToPage(table, c);
}, moveToFirstPage = function(table, c) {
c.page = 0;
moveToLastPage = function(table, c) { moveToPage(table, c);
c.page = ( Math.min( c.totalPages, c.filteredPages ) - 1 ); },
moveToPage(table, c);
}, moveToLastPage = function(table, c) {
c.page = ( Math.min( c.totalPages, c.filteredPages ) - 1 );
moveToNextPage = function(table, c) { moveToPage(table, c);
c.page++; },
if ( c.page >= ( Math.min( c.totalPages, c.filteredPages ) - 1 ) ) {
c.page = ( Math.min( c.totalPages, c.filteredPages ) - 1 ); moveToNextPage = function(table, c) {
} c.page++;
moveToPage(table, c); if ( c.page >= ( Math.min( c.totalPages, c.filteredPages ) - 1 ) ) {
}, c.page = ( Math.min( c.totalPages, c.filteredPages ) - 1 );
}
moveToPrevPage = function(table, c) { moveToPage(table, c);
c.page--; },
if ( c.page <= 0 ) {
c.page = 0; moveToPrevPage = function(table, c) {
} c.page--;
moveToPage(table, c); if ( c.page <= 0 ) {
}, c.page = 0;
}
destroyPager = function(table, c){ moveToPage(table, c);
showAllRows(table, c); },
$(c.container).hide(); // hide pager
table.config.appender = null; // remove pager appender function destroyPager = function(table, c){
$(table).unbind('destroy.pager sortEnd.pager filterEnd.pager enable.pager disable.pager'); showAllRows(table, c);
}, $(c.container).hide(); // hide pager
table.config.appender = null; // remove pager appender function
enablePager = function(table, c, triggered){ $(table).unbind('destroy.pager sortEnd.pager filterEnd.pager enable.pager disable.pager');
var p = $(c.cssPageSize, c.container).removeClass(c.cssDisabled).removeAttr('disabled'); },
c.isDisabled = false;
c.page = $.data(table, 'pagerLastPage') || c.page || 0; enablePager = function(table, c, triggered){
c.size = $.data(table, 'pagerLastSize') || parseInt(p.val(), 10) || c.size; var p = $(c.cssPageSize, c.container).removeClass(c.cssDisabled).removeAttr('disabled');
c.totalPages = Math.ceil( Math.min( c.totalPages, c.filteredPages ) / c.size); c.isDisabled = false;
if ( triggered ) { c.page = $.data(table, 'pagerLastPage') || c.page || 0;
$(table).trigger('update'); c.size = $.data(table, 'pagerLastSize') || parseInt(p.val(), 10) || c.size;
setPageSize(table, c.size, c); c.totalPages = Math.ceil( Math.min( c.totalPages, c.filteredPages ) / c.size);
hideRowsSetup(table, c); if ( triggered ) {
fixHeight(table, c); $(table).trigger('update');
} setPageSize(table, c.size, c);
}; hideRowsSetup(table, c);
fixHeight(table, c);
$this.appender = function(table, rows) { }
var c = table.config.pager; };
if ( !c.ajax ) {
table.config.rowsCopy = rows; $this.appender = function(table, rows) {
c.totalRows = rows.length; var c = table.config.pager;
c.size = $.data(table, 'pagerLastSize') || c.size; if ( !c.ajax ) {
c.totalPages = Math.ceil(c.totalRows / c.size); table.config.rowsCopy = rows;
renderTable(table, rows, c); c.totalRows = rows.length;
} c.size = $.data(table, 'pagerLastSize') || c.size;
}; c.totalPages = Math.ceil(c.totalRows / c.size);
renderTable(table, rows, c);
$this.construct = function(settings) { }
return this.each(function() { };
var config = this.config,
c = config.pager = $.extend( {}, $.tablesorterPager.defaults, settings ), $this.construct = function(settings) {
table = this, return this.each(function() {
$t = $(table), var config = this.config,
pager = $(c.container).addClass('tablesorter-pager').show(); // added in case the pager is reinitialized after being destroyed. c = config.pager = $.extend( {}, $.tablesorterPager.defaults, settings ),
config.appender = $this.appender; table = this,
enablePager(table, c, false); $t = $(table),
if ( typeof(c.ajaxUrl) === 'string' ) { pager = $(c.container).addClass('tablesorter-pager').show(); // added in case the pager is reinitialized after being destroyed.
// ajax pager; interact with database config.appender = $this.appender;
c.ajax = true; // clear initialized flag
getAjax(table, c); c.initialized = false;
} else { enablePager(table, c, false);
c.ajax = false; if ( typeof(c.ajaxUrl) === 'string' ) {
// Regular pager; all rows stored in memory // ajax pager; interact with database
$(this).trigger("appendCache", true); c.ajax = true;
hideRowsSetup(table, c); getAjax(table, c);
} } else {
c.ajax = false;
if ( $(table).hasClass('hasFilters') ) { // Regular pager; all rows stored in memory
$(table).unbind('filterEnd.pager').bind('filterEnd.pager', function() { $(this).trigger("appendCache", true);
c.page = 0; hideRowsSetup(table, c);
updatePageDisplay(table, c); }
moveToPage(table, c);
changeHeight(table, c); // update pager after filter widget completes
}); if ( $(table).hasClass('hasFilters') ) {
} $(table).unbind('filterEnd.pager').bind('filterEnd.pager', function() {
if ( $(c.cssGoto, pager).length ) { c.page = 0;
$(c.cssGoto, pager).bind('change', function(){ updatePageDisplay(table, c);
c.page = $(this).val() - 1; moveToPage(table, c);
moveToPage(table, c); changeHeight(table, c);
}); });
updatePageDisplay(table, c); }
} if ( $(c.cssGoto, pager).length ) {
$(c.cssFirst,pager).unbind('click.pager').bind('click.pager', function() { $(c.cssGoto, pager).bind('change', function(){
if ( !$(this).hasClass(c.cssDisabled) ) { moveToFirstPage(table, c); } c.page = $(this).val() - 1;
return false; moveToPage(table, c);
}); });
$(c.cssNext,pager).unbind('click.pager').bind('click.pager', function() { updatePageDisplay(table, c);
if ( !$(this).hasClass(c.cssDisabled) ) { moveToNextPage(table, c); } }
return false; $(c.cssFirst,pager).unbind('click.pager').bind('click.pager', function() {
}); if ( !$(this).hasClass(c.cssDisabled) ) { moveToFirstPage(table, c); }
$(c.cssPrev,pager).unbind('click.pager').bind('click.pager', function() { return false;
if ( !$(this).hasClass(c.cssDisabled) ) { moveToPrevPage(table, c); } });
return false; $(c.cssNext,pager).unbind('click.pager').bind('click.pager', function() {
}); if ( !$(this).hasClass(c.cssDisabled) ) { moveToNextPage(table, c); }
$(c.cssLast,pager).unbind('click.pager').bind('click.pager', function() { return false;
if ( !$(this).hasClass(c.cssDisabled) ) { moveToLastPage(table, c); } });
return false; $(c.cssPrev,pager).unbind('click.pager').bind('click.pager', function() {
}); if ( !$(this).hasClass(c.cssDisabled) ) { moveToPrevPage(table, c); }
$(c.cssPageSize,pager).unbind('change.pager').bind('change.pager', function() { return false;
$(c.cssPageSize,pager).val( $(this).val() ); // in case there are more than one pagers });
if ( !$(this).hasClass(c.cssDisabled) ) { $(c.cssLast,pager).unbind('click.pager').bind('click.pager', function() {
setPageSize(table, parseInt( $(this).val(), 10 ), c); if ( !$(this).hasClass(c.cssDisabled) ) { moveToLastPage(table, c); }
changeHeight(table, c); return false;
} });
return false; $(c.cssPageSize,pager).unbind('change.pager').bind('change.pager', function() {
}); $(c.cssPageSize,pager).val( $(this).val() ); // in case there are more than one pagers
if ( !$(this).hasClass(c.cssDisabled) ) {
$t setPageSize(table, parseInt( $(this).val(), 10 ), c);
.unbind('disable.pager enable.pager destroy.pager update.pager') changeHeight(table, c);
.bind('disable.pager', function(){ }
showAllRows(table, c); return false;
}) });
.bind('enable.pager', function(){
enablePager(table, c, true); $t
}) .unbind('disable.pager enable.pager destroy.pager update.pager')
.bind('destroy.pager', function(){ .bind('disable.pager', function(){
destroyPager(table, c); showAllRows(table, c);
}) })
.bind('update.pager', function(){ .bind('enable.pager', function(){
hideRows(table, c); enablePager(table, c, true);
}); })
}); .bind('destroy.pager', function(){
}; destroyPager(table, c);
})
}() .bind('update.pager', function(){
}); hideRows(table, c);
// extend plugin scope });
$.fn.extend({
tablesorterPager: $.tablesorterPager.construct // pager initialized
}); if (!c.ajax) {
c.initialized = true;
$(table).trigger('pagerInitialized', c);
}
});
};
}()
});
// extend plugin scope
$.fn.extend({
tablesorterPager: $.tablesorterPager.construct
});
})(jQuery); })(jQuery);

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "tablesorter", "name": "tablesorter",
"version": "2.4.3", "version": "2.4.4",
"title": "tablesorter", "title": "tablesorter",
"author": { "author": {
"name": "Christian Bach", "name": "Christian Bach",