retain pager size & total pages

This commit is contained in:
Rob Garrison 2011-10-28 08:12:37 -05:00
parent 628e0eeee8
commit 7b70cea518
4 changed files with 16 additions and 5 deletions

View File

@ -28,6 +28,10 @@ Included all original [document pages](http://mottie.github.com/tablesorter/docs
View the [complete listing here](http://mottie.github.com/tablesorter/changelog.txt).
#### Version 2.0.23.2 (2011-10-28)
* Fixed pager size & total pages not being retained after destroying, then restoring the pager. Thanks to crush123 for reporting the problem!
#### Version 2.0.23.1 (2011-10-26)
* Fixed the pager plugin to prevent errors when initialized on an empty table. Fix for [issue #5](https://github.com/Mottie/tablesorter/issues/5).

View File

@ -1,6 +1,6 @@
/*
* tablesorter pager plugin
* updated 10/26/2011
* updated 10/28/2011
*/
(function($) {
@ -65,7 +65,7 @@
},
hideRowsSetup = function(table, c){
c.size = parseInt($(c.cssPageSize, c.container).val(), 10);
c.size = c.lastSize = parseInt($(c.cssPageSize, c.container).val(), 10);
pagerArrows(c);
if (!c.removeRows) {
hideRows(table, c);
@ -110,6 +110,7 @@
showAllRows = function(table, c){
c.lastPage = c.page;
c.lastSize = c.size;
c.size = c.totalRows;
c.totalPages = 1;
renderTable(table, c.rowsCopy, c);
@ -176,6 +177,7 @@
var c = table.config;
c.rowsCopy = rows;
c.totalRows = rows.length;
c.size = c.lastSize || c.size;
c.totalPages = Math.ceil(c.totalRows / c.size);
renderTable(table, rows, c);
};

View File

@ -1,2 +1,2 @@
/* tablesorter pager plugin - updated 10/26/2011 */
(function(d){d.extend({tablesorterPager:new function(){var m=function(c){var a=c.cssDisabled;c.updateArrows&&(c.container[c.totalRows<c.size?"addClass":"removeClass"](a),d(c.cssFirst+","+c.cssPrev,c.container)[c.page===0?"addClass":"removeClass"](a),d(c.cssNext+","+c.cssLast,c.container)[c.page===c.totalPages-1?"addClass":"removeClass"](a))},q=function(c,a){a.startRow=a.size*a.page+1;a.endRow=Math.min(a.totalRows,a.size*(a.page+1));var b=d(a.cssPageDisplay,a.container),e=a.output.replace(/\{(page|totalPages|startRow|endRow|totalRows)\}/gi, function(b){return{"{page}":a.page+1,"{totalPages}":a.totalPages,"{startRow}":a.startRow,"{endRow}":a.endRow,"{totalRows}":a.totalRows}[b]});b[0].tagName==="INPUT"?b.val(e):b.html(e);m(a);a.container.show();d(c).trigger("pagerComplete",a)},n=function(c,a){var b=d(c);if(!a.pagerPositionSet&&a.positionFixed)b.offset&&a.container.css({top:b.offset().top+b.height()+a.offset+"px",position:"absolute"}),a.pagerPositionSet=true},j=function(c,a){var b,e=d("tr",c.tBodies[0]),g=e.length,f=a.page*a.size,i=f+ a.size;i>g&&(i=g);for(b=0;b<g;b++)e[b].style.display=b>=f&&b<i?"":"none"},o=function(c,a){a.size=parseInt(d(a.cssPageSize,a.container).val(),10);m(a);a.removeRows||(j(c,a),d(c).bind("sortEnd.pager",function(){j(c,a);d(c).trigger("applyWidgets")}))},h=function(c,a,b){var e,g,h,i=d(c.tBodies[0]),k=a.length;e=b.page*b.size;var l=e+b.size;if(!(k<1)){d(c).trigger("pagerChange",b);if(b.removeRows){if(l>a.length)l=a.length;for(d.tablesorter.clearTableBody(c);e<l;e++){h=a[e];k=h.length;for(g=0;g<k;g++)i[0].appendChild(h[g])}}else j(c, b);n(c,i,b);d(c).trigger("applyWidgets");if(b.page>=b.totalPages)b.page=b.totalPages-1,f(c,b);q(c,b)}},p=function(c,a){a.lastPage=a.page;a.size=a.totalRows;a.totalPages=1;h(c,a.rowsCopy,a)},f=function(c,a){if(!a.isDisabled){if(a.page<0||a.page>a.totalPages-1)a.page=0;h(c,a.rowsCopy,a)}};this.appender=function(c,a){var b=c.config;b.rowsCopy=a;b.totalRows=a.length;b.totalPages=Math.ceil(b.totalRows/b.size);h(c,a,b)};this.defaults={container:null,output:"{startRow} to {endRow} of {totalRows} rows",updateArrows:true, page:0,size:10,positionFixed:true,offset:0,removeRows:true,cssNext:".next",cssPrev:".prev",cssFirst:".first",cssLast:".last",cssPageDisplay:".pagedisplay",cssPageSize:".pagesize",cssDisabled:"disabled",totalRows:0,totalPages:0,appender:this.appender};this.construct=function(c){return this.each(function(){var a=d.extend(this.config,d.tablesorterPager.defaults,c),b=this,e=a.container;d(this).trigger("appendCache");o(b,a);d(a.cssFirst,e).unbind("click.pager").bind("click.pager",function(){a.page=0;f(b, a);return false});d(a.cssNext,e).unbind("click.pager").bind("click.pager",function(){a.page++;if(a.page>=a.totalPages-1)a.page=a.totalPages-1;f(b,a);return false});d(a.cssPrev,e).unbind("click.pager").bind("click.pager",function(){a.page--;if(a.page<=0)a.page=0;f(b,a);return false});d(a.cssLast,e).unbind("click.pager").bind("click.pager",function(){a.page=a.totalPages-1;f(b,a);return false});d(a.cssPageSize,e).unbind("change.pager").bind("change.pager",function(){var c=parseInt(d(this).val(),10); a.size=c;a.totalPages=Math.ceil(a.totalRows/a.size);a.pagerPositionSet=false;f(b,a);n(b,a);return false});d(this).unbind("disable.pager enable.pager destroy.pager").bind("disable.pager",function(){a.isDisabled=true;p(b,a)}).bind("enable.pager",function(){a.isDisabled=false;d("table").trigger("update");a.page=a.lastPage||0;a.totalPages=Math.ceil(a.totalRows/a.size);o(b,a)}).bind("destroy.pager",function(){p(b,a);a.container.hide();a.appender=null;d(b).unbind("destroy.pager sortEnd.pager enable.pager disable.pager")})})}}}); d.fn.extend({tablesorterPager:d.tablesorterPager.construct})})(jQuery);
/* tablesorter pager plugin - updated 10/28/2011 */
(function(d){d.extend({tablesorterPager:new function(){var m=function(c){var a=c.cssDisabled;c.updateArrows&&(c.container[c.totalRows<c.size?"addClass":"removeClass"](a),d(c.cssFirst+","+c.cssPrev,c.container)[c.page===0?"addClass":"removeClass"](a),d(c.cssNext+","+c.cssLast,c.container)[c.page===c.totalPages-1?"addClass":"removeClass"](a))},q=function(c,a){a.startRow=a.size*a.page+1;a.endRow=Math.min(a.totalRows,a.size*(a.page+1));var b=d(a.cssPageDisplay,a.container),e=a.output.replace(/\{(page|totalPages|startRow|endRow|totalRows)\}/gi, function(b){return{"{page}":a.page+1,"{totalPages}":a.totalPages,"{startRow}":a.startRow,"{endRow}":a.endRow,"{totalRows}":a.totalRows}[b]});b[0].tagName==="INPUT"?b.val(e):b.html(e);m(a);a.container.show();d(c).trigger("pagerComplete",a)},n=function(c,a){var b=d(c);if(!a.pagerPositionSet&&a.positionFixed)b.offset&&a.container.css({top:b.offset().top+b.height()+a.offset+"px",position:"absolute"}),a.pagerPositionSet=true},j=function(c,a){var b,e=d("tr",c.tBodies[0]),g=e.length,f=a.page*a.size,i=f+ a.size;i>g&&(i=g);for(b=0;b<g;b++)e[b].style.display=b>=f&&b<i?"":"none"},o=function(c,a){a.size=a.lastSize=parseInt(d(a.cssPageSize,a.container).val(),10);m(a);a.removeRows||(j(c,a),d(c).bind("sortEnd.pager",function(){j(c,a);d(c).trigger("applyWidgets")}))},h=function(c,a,b){var e,g,h,i=d(c.tBodies[0]),k=a.length;e=b.page*b.size;var l=e+b.size;if(!(k<1)){d(c).trigger("pagerChange",b);if(b.removeRows){if(l>a.length)l=a.length;for(d.tablesorter.clearTableBody(c);e<l;e++){h=a[e];k=h.length;for(g=0;g< k;g++)i[0].appendChild(h[g])}}else j(c,b);n(c,i,b);d(c).trigger("applyWidgets");if(b.page>=b.totalPages)b.page=b.totalPages-1,f(c,b);q(c,b)}},p=function(c,a){a.lastPage=a.page;a.lastSize=a.size;a.size=a.totalRows;a.totalPages=1;h(c,a.rowsCopy,a)},f=function(c,a){if(!a.isDisabled){if(a.page<0||a.page>a.totalPages-1)a.page=0;h(c,a.rowsCopy,a)}};this.appender=function(c,a){var b=c.config;b.rowsCopy=a;b.totalRows=a.length;b.size=b.lastSize||b.size;b.totalPages=Math.ceil(b.totalRows/b.size);h(c,a,b)}; this.defaults={container:null,output:"{startRow} to {endRow} of {totalRows} rows",updateArrows:true,page:0,size:10,positionFixed:true,offset:0,removeRows:true,cssNext:".next",cssPrev:".prev",cssFirst:".first",cssLast:".last",cssPageDisplay:".pagedisplay",cssPageSize:".pagesize",cssDisabled:"disabled",totalRows:0,totalPages:0,appender:this.appender};this.construct=function(c){return this.each(function(){var a=d.extend(this.config,d.tablesorterPager.defaults,c),b=this,e=a.container;d(this).trigger("appendCache"); o(b,a);d(a.cssFirst,e).unbind("click.pager").bind("click.pager",function(){a.page=0;f(b,a);return false});d(a.cssNext,e).unbind("click.pager").bind("click.pager",function(){a.page++;if(a.page>=a.totalPages-1)a.page=a.totalPages-1;f(b,a);return false});d(a.cssPrev,e).unbind("click.pager").bind("click.pager",function(){a.page--;if(a.page<=0)a.page=0;f(b,a);return false});d(a.cssLast,e).unbind("click.pager").bind("click.pager",function(){a.page=a.totalPages-1;f(b,a);return false});d(a.cssPageSize,e).unbind("change.pager").bind("change.pager", function(){var c=parseInt(d(this).val(),10);a.size=c;a.totalPages=Math.ceil(a.totalRows/a.size);a.pagerPositionSet=false;f(b,a);n(b,a);return false});d(this).unbind("disable.pager enable.pager destroy.pager").bind("disable.pager",function(){a.isDisabled=true;p(b,a)}).bind("enable.pager",function(){a.isDisabled=false;d("table").trigger("update");a.page=a.lastPage||0;a.totalPages=Math.ceil(a.totalRows/a.size);o(b,a)}).bind("destroy.pager",function(){p(b,a);a.container.hide();a.appender=null;d(b).unbind("destroy.pager sortEnd.pager enable.pager disable.pager")})})}}}); d.fn.extend({tablesorterPager:d.tablesorterPager.construct})})(jQuery);

View File

@ -1,7 +1,12 @@
TableSorter Change Log
Version 2.0.23.2 (2011-10-28)
============================
* Fixed pager size & total pages not being retained after destroying, then restoring the pager. Thanks to crush123 for reporting the problem!
Version 2.0.23.1 (2011-10-26)
============================]
============================
* Fixed the pager plugin to prevent errors when initialized on an empty table. Fix for [issue #5](https://github.com/Mottie/tablesorter/issues/5).
* Added a Resizable Column widget