mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
added pager savePages option. Fixes #345
This commit is contained in:
parent
0fd5203515
commit
2993069e04
@ -6,6 +6,8 @@
|
|||||||
;(function($) {
|
;(function($) {
|
||||||
"use strict";
|
"use strict";
|
||||||
/*jshint supernew:true */
|
/*jshint supernew:true */
|
||||||
|
var ts = $.tablesorter;
|
||||||
|
|
||||||
$.extend({ tablesorterPager: new function() {
|
$.extend({ tablesorterPager: new function() {
|
||||||
|
|
||||||
this.defaults = {
|
this.defaults = {
|
||||||
@ -56,6 +58,9 @@
|
|||||||
// Number of visible rows
|
// Number of visible rows
|
||||||
size: 10,
|
size: 10,
|
||||||
|
|
||||||
|
// Save pager page & size if the storage script is loaded (requires $.tablesorter.storage in jquery.tablesorter.widgets.js)
|
||||||
|
savePages: true,
|
||||||
|
|
||||||
// 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,
|
||||||
@ -139,7 +144,16 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
pagerArrows(p);
|
pagerArrows(p);
|
||||||
if (p.initialized && flag !== false) { c.$table.trigger('pagerComplete', p); }
|
if (p.initialized && flag !== false) {
|
||||||
|
c.$table.trigger('pagerComplete', p);
|
||||||
|
// save pager info to storage
|
||||||
|
if (p.savePages && ts.storage) {
|
||||||
|
ts.storage(table, 'tablesorter-pager', {
|
||||||
|
page : p.page,
|
||||||
|
size : p.size
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
fixHeight = function(table, p) {
|
fixHeight = function(table, p) {
|
||||||
@ -279,13 +293,15 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (c.showProcessing) {
|
if (c.showProcessing) {
|
||||||
$.tablesorter.isProcessing(table); // remove loading icon
|
ts.isProcessing(table); // remove loading icon
|
||||||
}
|
}
|
||||||
$t.trigger('update');
|
$t.trigger('update');
|
||||||
p.totalPages = Math.ceil( p.totalRows / p.size );
|
p.totalPages = Math.ceil( p.totalRows / p.size );
|
||||||
updatePageDisplay(table, p);
|
updatePageDisplay(table, p);
|
||||||
fixHeight(table, p);
|
fixHeight(table, p);
|
||||||
if (p.initialized) { $t.trigger('pagerChange', p); }
|
if (p.initialized) {
|
||||||
|
$t.trigger('pagerChange', p);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!p.initialized) {
|
if (!p.initialized) {
|
||||||
p.initialized = true;
|
p.initialized = true;
|
||||||
@ -299,7 +315,7 @@
|
|||||||
c = table.config;
|
c = table.config;
|
||||||
if ( url !== '' ) {
|
if ( url !== '' ) {
|
||||||
if (c.showProcessing) {
|
if (c.showProcessing) {
|
||||||
$.tablesorter.isProcessing(table, true); // show loading icon
|
ts.isProcessing(table, true); // show loading icon
|
||||||
}
|
}
|
||||||
$doc.bind('ajaxError.pager', function(e, xhr, settings, exception) {
|
$doc.bind('ajaxError.pager', function(e, xhr, settings, exception) {
|
||||||
renderAjax(null, table, p, xhr, exception);
|
renderAjax(null, table, p, xhr, exception);
|
||||||
@ -366,12 +382,12 @@
|
|||||||
if ( e > rows.length ) {
|
if ( e > rows.length ) {
|
||||||
e = rows.length;
|
e = rows.length;
|
||||||
}
|
}
|
||||||
$.tablesorter.clearTableBody(table);
|
ts.clearTableBody(table);
|
||||||
$tb = $.tablesorter.processTbody(table, table.config.$tbodies.eq(0), true);
|
$tb = ts.processTbody(table, table.config.$tbodies.eq(0), true);
|
||||||
for ( i = s; i < e; i++ ) {
|
for ( i = s; i < e; i++ ) {
|
||||||
$tb.append(rows[i]);
|
$tb.append(rows[i]);
|
||||||
}
|
}
|
||||||
$.tablesorter.processTbody(table, $tb, false);
|
ts.processTbody(table, $tb, false);
|
||||||
}
|
}
|
||||||
if ( p.page >= p.totalPages ) {
|
if ( p.page >= p.totalPages ) {
|
||||||
moveToLastPage(table, p);
|
moveToLastPage(table, p);
|
||||||
@ -500,6 +516,12 @@
|
|||||||
p.oldAjaxSuccess = p.oldAjaxSuccess || p.ajaxObject.success;
|
p.oldAjaxSuccess = p.oldAjaxSuccess || p.ajaxObject.success;
|
||||||
c.appender = $this.appender;
|
c.appender = $this.appender;
|
||||||
|
|
||||||
|
if (p.savePages && ts.storage) {
|
||||||
|
t = ts.storage(table, 'tablesorter-pager');
|
||||||
|
p.page = isNaN(t.page) ? p.page : t.page;
|
||||||
|
p.size = isNaN(t.size) ? p.size : t.size;
|
||||||
|
}
|
||||||
|
|
||||||
$t
|
$t
|
||||||
.unbind('filterStart.pager filterEnd.pager sortEnd.pager disable.pager enable.pager destroy.pager update.pager pageSize.pager')
|
.unbind('filterStart.pager filterEnd.pager sortEnd.pager disable.pager enable.pager destroy.pager update.pager pageSize.pager')
|
||||||
.bind('filterStart.pager', function(e, filters) {
|
.bind('filterStart.pager', function(e, filters) {
|
||||||
@ -578,7 +600,6 @@
|
|||||||
p.page = $(this).val() - 1;
|
p.page = $(this).val() - 1;
|
||||||
moveToPage(table, p);
|
moveToPage(table, p);
|
||||||
});
|
});
|
||||||
updatePageDisplay(table, p, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// page size selector
|
// page size selector
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
<!-- Tablesorter: required -->
|
<!-- Tablesorter: required -->
|
||||||
<link rel="stylesheet" href="../css/theme.blue.css">
|
<link rel="stylesheet" href="../css/theme.blue.css">
|
||||||
<script src="../js/jquery.tablesorter.js"></script>
|
<script src="../js/jquery.tablesorter.js"></script>
|
||||||
|
<script src="../js/jquery.tablesorter.widgets.js"></script>
|
||||||
|
|
||||||
<!-- Tablesorter: optional -->
|
<!-- Tablesorter: optional -->
|
||||||
<link rel="stylesheet" href="../addons/pager/jquery.tablesorter.pager.css">
|
<link rel="stylesheet" href="../addons/pager/jquery.tablesorter.pager.css">
|
||||||
@ -59,6 +60,9 @@
|
|||||||
// Number of visible rows - default is 10
|
// Number of visible rows - default is 10
|
||||||
size: 10,
|
size: 10,
|
||||||
|
|
||||||
|
// Save pager page & size if the storage script is loaded (requires $.tablesorter.storage in jquery.tablesorter.widgets.js)
|
||||||
|
savePages : true,
|
||||||
|
|
||||||
// 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: true,
|
fixedHeight: true,
|
||||||
@ -192,6 +196,7 @@
|
|||||||
<ul>
|
<ul>
|
||||||
<li>This pager plugin can be applied to the original tablesorter, but there is one exception - setting the <code>removeRows</code> option to false will break the sort.</li>
|
<li>This pager plugin can be applied to the original tablesorter, but there is one exception - setting the <code>removeRows</code> option to false will break the sort.</li>
|
||||||
<li>There have been lots of changes made in version 2.1, please check out the <a href="https://github.com/Mottie/tablesorter/wiki/Change2">change log</a>.</li>
|
<li>There have been lots of changes made in version 2.1, please check out the <a href="https://github.com/Mottie/tablesorter/wiki/Change2">change log</a>.</li>
|
||||||
|
<li>In <span class="version">v2.11</span>, the <code>savePages</code> option was added to saves the current page size and number (requires storage script).</li>
|
||||||
</ul>
|
</ul>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
@ -2640,6 +2640,14 @@ $.extend($.tablesorter.themes.jui, {
|
|||||||
<td><a href="example-pager.html">Example</a></td>
|
<td><a href="example-pager.html">Example</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
<tr id="save-pages">
|
||||||
|
<td><span class="permalink">savePages</span></td>
|
||||||
|
<td>Boolean</td>
|
||||||
|
<td>true</td>
|
||||||
|
<td>Saves the current pager page size and number. This option requires the <code>$.tablesorter.storage</code> script in the <code>jquery.tablesorter.widgets.js</code> file (<span class="version">v2.11</span>).</td>
|
||||||
|
<td><a href="example-pager.html">Example</a></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
<tr id="pager-fixedheight">
|
<tr id="pager-fixedheight">
|
||||||
<td><a href="#" class="toggle2">fixedHeight</a></td>
|
<td><a href="#" class="toggle2">fixedHeight</a></td>
|
||||||
<td>Boolean</td>
|
<td>Boolean</td>
|
||||||
|
Loading…
Reference in New Issue
Block a user