sortBegin & removeRows - pager

This commit is contained in:
Rob Garrison 2011-09-22 17:32:58 -05:00
parent ce8ae429c7
commit 1f8a9ce203
7 changed files with 69 additions and 30 deletions

View File

@ -28,6 +28,15 @@ 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.21 (2011-09-22)
* Added `sortBegin` event
* This event is triggered immediately before the actual sort. So this event occurs after the `sortStart` and after the `sortList` option has been updated.
* It was added to allow for changing the sort dynamically. See [issue #3](https://github.com/Mottie/tablesorter/issues/3).
* Added `removeRows` option to the pager plugin
* When `true`, the default value, the pager plugin removes all non-active rows from the table. This greatly increases the sort speed of large tables.
* When `false`, the pager plugin merely hides the non-active rows so they all continue to exist in the table. This should allow for better access to data within the table (i.e. submitting form elements)
#### Version 2.0.20.1 (2011-09-16)
* Oops fixed currency sorting

View File

@ -60,6 +60,17 @@
}
},
hideRows = function(table, c){
var i, rows = $('tr', table.tBodies[0]),
l = rows.length,
s = (c.page * c.size),
e = (s + c.size);
if (e > l) { e = l; }
for (i = 0; i < l; i++){
rows[i].style.display = (i >= s && i < e) ? '' : 'none';
}
},
renderTable = function(table,rows) {
var i, j, o,
tableBody,
@ -68,23 +79,27 @@
s = (c.page * c.size),
e = (s + c.size);
$(table).trigger('pagerChange',c);
if (e > rows.length ) {
e = rows.length;
}
tableBody = $(table.tBodies[0]);
// clear the table body
$.tablesorter.clearTableBody(table);
for(i = s; i < e; i++) {
//tableBody.append(rows[i]);
o = rows[i];
l = o.length;
for (j = 0; j < l; j++) {
tableBody[0].appendChild(o[j]);
if (!c.removeRows) {
hideRows(table, c);
} else {
if (e > rows.length ) {
e = rows.length;
}
tableBody = $(table.tBodies[0]);
// clear the table body
$.tablesorter.clearTableBody(table);
for(i = s; i < e; i++) {
//tableBody.append(rows[i]);
o = rows[i];
l = o.length;
for (j = 0; j < l; j++) {
tableBody[0].appendChild(o[j]);
}
}
}
fixPosition(table,tableBody);
$(table).trigger("applyWidgets");
if( c.page >= c.totalPages ) {
if ( c.page >= c.totalPages ) {
moveToLastPage(table);
}
updatePageDisplay(table,c);
@ -145,8 +160,7 @@
// hide pager
c.container.hide();
c.appender = null;
$(table).unbind('destroy.pager');
$(table).unbind('destroy.pager sortStart.pager');
};
this.appender = function(table,rows) {
@ -174,6 +188,7 @@
output: '{page}/{totalPages}', // '{startRow} to {endRow} of {totalRows} rows',
updateArrows: false,
positionFixed: true,
removeRows: true, // removing rows in larger tables speeds up the sort
appender: this.appender
};
@ -186,6 +201,14 @@
config.size = parseInt($(".pagesize",pager).val(), 10);
pagerArrows(config);
if (!config.removeRows) {
config.appender = null;
hideRows(table, config);
$(this).bind('sortEnd.pager', function(){
hideRows(table, config);
$(table).trigger("applyWidgets");
});
}
$(config.cssFirst,pager).click(function() {
moveToFirstPage(table);

View File

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

View File

@ -1,5 +1,15 @@
TableSorter Change Log
Version 2.0.21 (2011-09-22)
============================
* Added `sortBegin` event
* This event is triggered immediately before the actual sort. So this event occurs after the `sortStart` and after the `sortList` option has been updated.
* It was added to allow for changing the sort dynamically. See [issue #3](https://github.com/Mottie/tablesorter/issues/3).
* Added `removeRows` option to the pager plugin
* When `true`, the default value, the pager plugin removes all non-active rows from the table. This greatly increases the sort speed of large tables.
* When `false`, the pager plugin merely hides the non-active rows so they all continue to exist in the table. This should allow for better access to data within the table (i.e. submitting form elements)
Version 2.0.20.1 (2011-09-16)
============================

View File

@ -13,7 +13,7 @@ jQuery.fn.antispam = function() {
$(function(){
$("a.external").each(function() {this.target = '_new'});
$("a.external").each(function() {this.target = '_new'});
$("span.email").antispam();
// get javascript source
@ -24,11 +24,7 @@ $(function(){
$("pre.css").text( $("#css").html().replace(/\t/g, " ") );
}
if ($("#demo").length) {
$("#html pre").text(
$("#demo").html()
.replace(/\t/g, " ")
// .replace(/[<>]/g, function(m){ return {'<':'&lt;','>':'&gt;'}[m]; })
);
$("#html pre").text( $("#demo").html().replace(/\t/g, " ") );
}
// hide child rows

View File

@ -966,20 +966,21 @@
ts.addWidget({
id: "zebra",
format: function(table) {
var $tr, row = -1,
odd, time;
var $tr, row = 0, even, time,
child = table.config.cssChildRow,
css = table.config.widgetZebra.css;
if (table.config.debug) {
time = new Date();
}
// loop through the visible rows
$("tr:visible", table.tBodies[0]).each(function (i) {
$("tr:visible", table.tBodies[0]).each(function(i){
$tr = $(this);
// style children rows the same way the parent row was styled
if (!$tr.hasClass(table.config.cssChildRow)) { row++; }
odd = (row % 2 === 0);
if (!$tr.hasClass(child)) { row++; }
even = (row % 2 === 0);
$tr
.removeClass(table.config.widgetZebra.css[odd ? 0 : 1])
.addClass(table.config.widgetZebra.css[odd ? 1 : 0]);
.removeClass(css[even ? 1 : 0])
.addClass(css[even ? 0 : 1]);
});
if (table.config.debug) {
$.tablesorter.benchmark("Applying Zebra widget", time);

File diff suppressed because one or more lines are too long