NOTE!
- In v2.28.4, added
data-pager-output
anddata-pager-output-filtered
attributes which override theoutput
option when set on thepageDisplay
element. - In v2.26.0, a page size of "all" instead of a specific number will be saved and used on reload. Also, ajax interaction will pass a size of "all" which may break current server methods on number of pages to return.
- In v2.25.4, updated example to use
applyWidgetId
to re-apply the pager widget after being destroyed. - In v2.24.0, a page size select option with a value of "all" will display all rows - not recommended for ajax interactions!
- In v2.19.0, added
pageAndSize
method which allows setting both the pager page & size. - In v2.17.6, added
{startRow:input}
and{page:input}
variables to theoutput
option. - This pager WIDGET can not be applied to the original tablesorter.
- Do not use this widget along with the pager plugin.
- The pager.css file also works with this pager widget.
- This widget is still in development as it has not been throughly tested.
- Extensive documentation has not been included, as all functioning is essentially identical to the pager addon, but here are some important differences:
- All of the options are now set within the
widgetOptions
. - Pager events (pagerChange pagerComplete pagerInitialized pageMoved) now return
table.config
instead oftable.config.pager
. - Most option names have only been modified by adding
pager_
as a prefix. - Exceptions include moving all applied css class names into a
pager_css
option and all selectors intopager_selectors
, including the originalcontainer
option. - Because I stopped trying so hard to make widgets compatible with jQuery v1.2.6, this widget requires at least v1.3+.
- See the Javascript code below for a full example.
- All of the options are now set within the
Triggered Events
- Pager events will appear here.
Demo




Name |
Major |
Sex |
English |
Japanese |
Calculus |
Geometry |
|
---|---|---|---|---|---|---|---|
Name | Major | Sex | English | Japanese | Calculus | Geometry | |
Student01 | Languages | male | 80 | 70 | 75 | 80 | |
Student02 | Mathematics | male | 90 | 88 | 100 | 90 | |
Student03 | Languages | female | 85 | 95 | 80 | 85 | |
Student04 | Languages | male | 60 | 55 | 100 | 100 | |
Student05 | Languages | female | 68 | 80 | 95 | 80 | |
Student06 | Mathematics | male | 100 | 99 | 100 | 90 | |
Student07 | Mathematics | male | 85 | 68 | 90 | 90 | |
Student08 | Languages | male | 100 | 90 | 90 | 85 | |
Student09 | Mathematics | male | 80 | 50 | 65 | 75 | |
Student10 | Languages | male | 85 | 100 | 100 | 90 |




Javascript
$(function() {
var $table = $('table');
$table
// Initialize tablesorter
// ***********************
.tablesorter({
theme: 'blue',
widthFixed: true,
widgets: ['zebra', 'filter', 'pager'],
widgetOptions: {
// ** NOTE: All default ajax options have been removed from this demo,
// see the example-widget-pager-ajax demo for a full list of pager
// options
// css class names that are added
pager_css: {
container : 'tablesorter-pager', // class added to make included pager.css file work
errorRow : 'tablesorter-errorRow', // error information row (don't include period at beginning); styled in theme file
disabled : 'disabled' // class added to arrows @ extremes (i.e. prev/first arrows "disabled" on first page)
},
// jQuery selectors
pager_selectors: {
container : '.pager', // target the pager markup (wrapper)
first : '.first', // go to first page arrow
prev : '.prev', // previous page arrow
next : '.next', // next page arrow
last : '.last', // go to last page arrow
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
},
// output default: '{page}/{totalPages}'
// possible variables: {size}, {page}, {totalPages}, {filteredPages}, {startRow}, {endRow}, {filteredRows} and {totalRows}
// also {page:input} & {startRow:input} will add a modifiable input in place of the value
pager_output: '{startRow:input} – {endRow} / {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 to this page after filtering; set to desired page number
// (zero-based index), or false to not change page at filter start
pager_pageReset: 0,
// Number of visible rows
pager_size: 10,
// f true, child rows will be counted towards the pager set size
pager_countChildRows: false,
// Save pager page & size if the storage script is loaded (requires $.tablesorter.storage in jquery.tablesorter.widgets.js)
pager_savePages: true,
// Saves tablesorter paging to custom key if defined. Key parameter name
// used by the $.tablesorter.storage function. Useful if you have
// multiple tables defined
pager_storageKey: "tablesorter-pager",
// if true, the table will remain the same height no matter how many records are displayed. The space is made up by an empty
// table row set to a height to compensate; default is false
pager_fixedHeight: true,
// 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.
pager_removeRows: false // removing rows in larger tables speeds up the sort
}
})
// bind to pager events
// *********************
.bind('pagerChange pagerComplete pagerInitialized pageMoved', function(e, c) {
var p = c.pager, // NEW with the widget... it returns config, instead of config.pager
msg = '"</span> event triggered, ' + (e.type === 'pagerChange' ? 'going to' : 'now on') +
' page <span class="typ">' + (p.page + 1) + '/' + p.totalPages + '</span>';
$('#display')
.append('<li><span class="str">"' + e.type + msg + '</li>')
.find('li:first').remove();
})
// Add two new rows using the "addRows" method
// the "update" method doesn't work here because not all rows are
// present in the table when the pager is applied ("removeRows" is false)
// ***********************************************************************
var r, $row, num = 50,
row = '<tr><td>Student{i}</td><td>{m}</td><td>{g}</td><td>{r}</td><td>{r}</td><td>{r}</td><td>{r}</td><td><button type="button" class="remove" title="Remove this row">X</button></td></tr>' +
'<tr><td>Student{j}</td><td>{m}</td><td>{g}</td><td>{r}</td><td>{r}</td><td>{r}</td><td>{r}</td><td><button type="button" class="remove" title="Remove this row">X</button></td></tr>';
$('button:contains(Add)').click(function() {
// add two rows of random data!
r = row.replace(/\{[gijmr]\}/g, function(m) {
return {
'{i}' : num + 1,
'{j}' : num + 2,
'{r}' : Math.round(Math.random() * 100),
'{g}' : Math.random() > 0.5 ? 'male' : 'female',
'{m}' : Math.random() > 0.5 ? 'Mathematics' : 'Languages'
}[m];
});
num = num + 2;
$row = $(r);
$table
.find('tbody').append($row)
.trigger('addRows', [$row]);
return false;
});
// Delete a row
// *************
$table.delegate('button.remove', 'click' ,function() {
// disabling the pager will restore all table rows
// $table.trigger('disablePager');
// remove chosen row
$(this).closest('tr').remove();
// restore pager
// $table.trigger('enablePager');
$table.trigger('update');
return false;
});
// Destroy pager / Restore pager
// **************
$('button:contains(Destroy)').click(function() {
// Exterminate, annhilate, destroy! http://www.youtube.com/watch?v=LOqn8FxuyFs
var $t = $(this);
if (/Destroy/.test( $t.text() )) {
$table.trigger('destroyPager');
$t.text('Restore Pager');
} else {
$('table').trigger('applyWidgetId', 'pager');
$t.text('Destroy Pager');
}
return false;
});
// Disable / Enable
// **************
$('.toggle').click(function() {
var mode = /Disable/.test( $(this).text() );
// using disablePager or enablePager
$table.trigger( (mode ? 'disable' : 'enable') + 'Pager');
$(this).text( (mode ? 'Enable' : 'Disable') + 'Pager');
return false;
});
$table.bind('pagerChange', function() {
// pager automatically enables when table is sorted.
$('.toggle').text('Disable Pager');
});
// clear storage (page & size)
$('.clear-pager-data').click(function() {
// clears user set page & size from local storage, so on page
// reload the page & size resets to the original settings
$.tablesorter.storage( $table, 'tablesorter-pager', '' );
});
// go to page 1 showing 10 rows
$('.goto').click(function() {
// triggering "pageAndSize" without parameters will reset the
// pager to page 1 and the original set size (10 by default)
// $('table').trigger('pageAndSize')
$table.trigger('pageAndSize', [1, 10]);
});
});
CSS
/* pager wrapper, div */
.tablesorter-pager {
padding: 5px;
}
/* pager wrapper, in thead/tfoot */
td.tablesorter-pager {
background-color: #e6eeee;
margin: 0; /* needed for bootstrap .pager gets a 18px bottom margin */
}
/* pager navigation arrows */
.tablesorter-pager img {
vertical-align: middle;
margin-right: 2px;
cursor: pointer;
}
/* pager output text */
.tablesorter-pager .pagedisplay {
padding: 0 5px 0 5px;
width: 50px;
text-align: center;
}
/* pager element reset (needed for bootstrap) */
.tablesorter-pager select {
margin: 0;
padding: 0;
}
/*** css used when "updateArrows" option is true ***/
/* the pager itself gets a disabled class when the number of rows is less than the size */
.tablesorter-pager.disabled {
display: none;
}
/* hide or fade out pager arrows when the first or last row is visible */
.tablesorter-pager .disabled {
/* visibility: hidden */
opacity: 0.5;
filter: alpha(opacity=50);
cursor: default;
}
HTML
<!-- jQuery -->
<script src="js/jquery-latest.min.js"></script>
<!-- Tablesorter: required -->
<link href="css/theme.blue.css" rel="stylesheet">
<script src="js/jquery.tablesorter.js"></script>
<script src="js/jquery.tablesorter.widgets.js"></script>
<!-- Tablesorter: pager widget -->
<link href="css/jquery.tablesorter.pager.css" rel="stylesheet">
<script src="js/widget-pager.js"></script>
<table class="tablesorter">
<!-- view page source to see the entire table -->
</table>
<!-- pager -->
<div id="pager" class="pager">
<form>
<img src="first.png" class="first"/>
<img src="prev.png" class="prev"/>
<!-- the "pagedisplay" can be any element, including an input -->
<span class="pagedisplay" data-pager-output-filtered="{startRow:input} – {endRow} / {filteredRows} of {totalRows} total rows"></span>
<img src="next.png" class="next"/>
<img src="last.png" class="last"/>
<select class="pagesize">
<option value="10">10</option>
<option value="20">20</option>
<option value="30">30</option>
<option value="40">40</option>
<option value="all">All Rows</option>
</select>
</form>
</div>
Pager Change Log
- Moved to wiki pages.