We have been using tablesorter programmed by Mottie for a good while now and a user has asked us if the pager can be automatically disabled when the user sorts by any column.
If you click on the following link https://mottie.github.io/tablesorter/docs/example-widget-pager.html, you'll see a Demo table. Press "Disable Pager" to see all 50 rows. Then sort by "Major" column, you'll see that it automatically reverts back to a paged view with 10 rows.
Now i know that the third button allows the pager to be destroyed to get around this but i would prefer to somehow stop the pager from defaulting to paged view after sorting. is this possible?? The reason for that is we just use the one button that toggles the pager on/off in our application.
The pager wasn't set up to stay disabled, but with a bit of code you can tweak it to your requirements (demo)
I added this button inside the pager container
<button type="button" class="toggle">Disable</button>
and used this code:
var $table = $('table'),
$pager = $('.pager'),
pagerDisabled = false,
savedPageSize = 10,
disabledPageSize = 9999;
$table
.tablesorter({
theme: 'blue',
widgets: ['zebra', 'columns']
})
.tablesorterPager({
container: $pager
});
$pager.find('.toggle').on('click', function(){
pagerDisabled = !pagerDisabled;
var pager = $table[0].config.pager;
if (pager.size !== disabledPageSize) {
// save user set page size
savedPageSize = pager.size;
}
if (!pagerDisabled) {
// set pagerLastSize before enabling pager
$table.data('pagerLastSize', savedPageSize);
}
// toggle pager state
$table.trigger( ( pagerDisabled ? 'disable' : 'enable' ) + '.pager');
// change button text
$(this).html( pagerDisabled ? 'Enable' : 'Disable' );
if (pagerDisabled) {
// set pagerLastSize after disabling pager
$table.data('pagerLastSize', disabledPageSize);
}
});