NOTE! The following are not part of the original plugin:
- When using this pager plugin with the filter widget, make sure that the
removeRows
option is set tofalse
or it won't work. - This combination was not possible in tablesorter versions prior to version 2.4.
- This combination can not be applied to the original tablesorter.
Demo
Page:
1 - 10 / 50 (50)




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 |
Page:
1 - 10 / 50 (50)




Javascript
$(function(){ // define pager options var pagerOptions = { // target the pager markup - see the HTML block below container: $(".pager"), // output string - default is '{page}/{totalPages}'; possible variables: {page}, {totalPages}, {startRow}, {endRow} and {totalRows} output: '{startRow} - {endRow} / {filteredRows} ({totalRows})', // if true, the table will remain the same height no matter how many records are displayed. The space is made up by an empty // table row set to a height to compensate; default is false fixedHeight: 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. removeRows: false, // go to page selector - select dropdown that sets the current page cssGoto: '.gotoPage' }; // Initialize tablesorter // *********************** $("table") .tablesorter({ theme: 'blue', headerTemplate : '{content} {icon}', // new in v2.7. Needed to add the bootstrap icon! widthFixed: true, widgets: ['zebra', 'filter'] }) // initialize the pager plugin // **************************** .tablesorterPager(pagerOptions); // 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 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 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]); }); // Delete a row // ************* $('table').delegate('button.remove', 'click' ,function(){ var t = $('table'); // disabling the pager will restore all table rows t.trigger('disable.pager'); // remove chosen row $(this).closest('tr').remove(); // restore pager t.trigger('enable.pager'); }); // 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('destroy.pager'); $t.text('Restore Pager'); } else { $('table').tablesorterPager(pagerOptions); $t.text('Destroy Pager'); } }); // Disable / Enable // ************** $('.toggle').click(function(){ var mode = /Disable/.test( $(this).text() ); $('table').trigger( (mode ? 'disable' : 'enable') + '.pager'); $(this).text( (mode ? 'Enable' : 'Disable') + 'Pager'); }); $('table').bind('pagerChange', function(){ // pager automatically enables when table is sorted. $('.toggle').text('Disable'); }); });