diff --git a/README.markdown b/README.markdown index 7ac8d42f..f752e89a 100644 --- a/README.markdown +++ b/README.markdown @@ -42,6 +42,7 @@ View the [complete listing here](http://mottie.github.com/tablesorter/changelog. * The `sortInitialOrder` will work in either the main options or specifically within the headers option when a particular column needs a different initial sort order. * Added a [sortReset/sortRestart](http://mottie.github.com/tablesorter/docs/example-option-sortreset-sortrestart.html) demo. * Resolves [issue #30](https://github.com/Mottie/tablesorter/issues/29). +* Updated pager plugin to better work with the sticky header widget. #### Version 2.1 (3/7/2012) diff --git a/addons/pager/jquery.tablesorter.pager.css b/addons/pager/jquery.tablesorter.pager.css index 3914697b..38a715e2 100644 --- a/addons/pager/jquery.tablesorter.pager.css +++ b/addons/pager/jquery.tablesorter.pager.css @@ -24,4 +24,15 @@ div.tablesorterPager input { background: rgba(255,255,255,0.8) url(icons/loading.gif) center center no-repeat; position: absolute; z-index: 1000; +} +/*** css used when "updateArrows" option is true ***/ +/* the pager itself gets a disabled class when the number of rows is less than the size */ +.pager.disabled { + display: none; +} +/* hide or fade out pager arrows when the first or last row is visible */ +.pager img.disabled { + /* visibility: hidden */ + opacity: 0.5; + filter: alpha(opacity=50); } \ No newline at end of file diff --git a/addons/pager/jquery.tablesorter.pager.js b/addons/pager/jquery.tablesorter.pager.js index 44cf3bd1..3971cd3c 100644 --- a/addons/pager/jquery.tablesorter.pager.js +++ b/addons/pager/jquery.tablesorter.pager.js @@ -1,6 +1,6 @@ /* * tablesorter pager plugin - * updated 3/7/2012 + * updated 3/8/2012 */ (function($) { @@ -149,7 +149,9 @@ // process data if (typeof(c.ajaxProcessing) === "function") { var result = c.ajaxProcessing(data), d = result[0], l = d.length, - i, k, th = [], tds = '', tf = ''; + i, k, th = [], tds = '', tf = '', hsh = $(table).addClass('hasStickyHeaders'), + sh = '.' + ((table.config.widgetOptions && table.config.widgetOptions.stickyHeaders) || 'tablesorter-stickyheader'), + $sh = $t.find(sh); for ( i=0; i < l; i++ ) { tds += ''; for (k in d[i]) { @@ -162,11 +164,17 @@ } tds += ''; } - $t.find('thead th').each(function(j){ + $t.find('thead tr.tablesorter-header th').each(function(j){ var $t = $(this), // add new test within the first span it finds, or just in the header tar = ($t.find('span').length) ? $t.find('span:first') : $t; - $t.html(th[j]); + tar.html(th[j]); + // update sticky headers + if (hsh && $sh.length){ + tar = $sh.find('th').eq(j); + tar = (tar.find('span').length) ? tar.find('span:first') : tar; + tar.html(th[j]); + } tf += '' + th[j] + ''; }); $t.find('tfoot').html('' + tf + ''); diff --git a/addons/pager/jquery.tablesorter.pager.min.js b/addons/pager/jquery.tablesorter.pager.min.js index 7976a102..7cf75d89 100644 --- a/addons/pager/jquery.tablesorter.pager.min.js +++ b/addons/pager/jquery.tablesorter.pager.min.js @@ -1,3 +1,3 @@ -/* tablesorter pager plugin minified - updated 3/7/2012 */ +/* tablesorter pager plugin minified - updated 3/8/2012 */ -(function(d){d.extend({tablesorterPager:new function(){this.defaults={container:null,ajaxUrl:null,ajaxProcessing:function(){return[[{key:"value"}],100]},output:"{startRow} to {endRow} of {totalRows} rows",updateArrows:!0,page:0,size:10,fixedHeight:!1,removeRows:!0,cssNext:".next",cssPrev:".prev",cssFirst:".first",cssLast:".last",cssPageDisplay:".pagedisplay",cssPageSize:".pagesize",cssDisabled:"disabled",totalRows:0,totalPages:0};var h=this,i=function(c,a){var b=c.cssDisabled,e=!!a;c.updateArrows&& (c.container[c.totalRows')},p=function(c,a){var b, e=d("tr:not(."+c.config.cssChildRow+")",c.tBodies[0]),g=e.length,f=a.page*a.size,m=f+a.size;m>g&&(m=g);for(b=0;b=f&&b", {id:"tablesorterPagerLoading",width:e.outerWidth(!0),height:e.outerHeight(!0)}),e.before(b),d.getJSON(f,function(f){if("function"===typeof a.ajaxProcessing){var f=a.ajaxProcessing(f),q=f[0],j=q.length,l,o,h=[],k="",i="";for(l=0;l";for(o in q[l])"string"===typeof o&&(0===l&&h.push(o),k+=""+q[l][o]+"");k+=""}e.find("thead th").each(function(a){var b=d(this);b.find("span").length&&b.find("span:first");b.html(h[a]);i+=""+h[a]+""});e.find("tfoot").html(""+i+""); g.html(k);b.remove();e.trigger("update");a.totalRows=f[1];a.totalPages=Math.ceil(a.totalRows/a.size);s(c,a);n(c,a);e.trigger("pagerChange",a)}}))},r=function(c,a,b){var e,g,f,m=d(c.tBodies[0]),h=a.length;e=b.page*b.size;var i=e+b.size;if(!(1>h)){d(c).trigger("pagerChange",b);if(b.removeRows){i>a.length&&(i=a.length);for(d(c.tBodies[0]).empty();e=b.totalPages&&(b.page=b.totalPages-1,j(c, b));s(c,b);b.isDisabled||n(c,b)}},v=function(c,a){a.ajax?i(a,!0):(a.isDisabled=!0,d.data(c,"pagerLastPage",a.page),d.data(c,"pagerLastSize",a.size),a.page=0,a.size=a.totalRows,a.totalPages=1,d("tr.pagerSavedHeightSpacer",c.tBodies[0]).remove(),r(c,c.config.rowsCopy,a));d(a.cssPageSize,a.container).addClass(a.cssDisabled)[0].disabled=!0},j=function(c,a){if(!a.isDisabled){if(0>a.page||a.page>a.totalPages-1)a.page=0;d.data(c,"pagerLastPage",a.page);a.ajax?u(c,a):r(c,c.config.rowsCopy,a)}},w=function(c, a,b){b.size=a;d.data(c,"pagerLastPage",b.page);d.data(c,"pagerLastSize",b.size);b.totalPages=Math.ceil(b.totalRows/b.size);j(c,b)},x=function(c,a,b){var e=d(a.cssPageSize,a.container).removeClass(a.cssDisabled).removeAttr("disabled");a.isDisabled=!1;a.page=d.data(c,"pagerLastPage")||0;a.size=d.data(c,"pagerLastSize")||parseInt(e.val(),10);a.totalPages=Math.ceil(a.totalRows/a.size);b&&(d("table").trigger("update"),w(c,a.size,a),t(c,a),n(c,a))};h.appender=function(c,a){var b=c.config.pager;b.ajax|| (c.config.rowsCopy=a,b.totalRows=a.length,b.size=d.data(c,"pagerLastSize")||b.size,b.totalPages=Math.ceil(b.totalRows/b.size),r(c,a,b))};h.construct=function(c){return this.each(function(){var a=this.config,b=a.pager=d.extend({},d.tablesorterPager.defaults,c),e=this,g=d(e),f=d(b.container).show();a.appender=h.appender;x(e,b,!1);"string"===typeof b.ajaxUrl?(b.ajax=!0,u(e,b)):(b.ajax=!1,d(this).trigger("appendCache"),t(e,b));d(b.cssFirst,f).unbind("click.pager").bind("click.pager",function(){if(!d(this).hasClass(b.cssDisabled)){b.page= 0;j(e,b)}return false});d(b.cssNext,f).unbind("click.pager").bind("click.pager",function(){if(!d(this).hasClass(b.cssDisabled)){b.page++;if(b.page>=b.totalPages-1)b.page=b.totalPages-1;j(e,b)}return false});d(b.cssPrev,f).unbind("click.pager").bind("click.pager",function(){if(!d(this).hasClass(b.cssDisabled)){b.page--;if(b.page<=0)b.page=0;j(e,b)}return false});d(b.cssLast,f).unbind("click.pager").bind("click.pager",function(){if(!d(this).hasClass(b.cssDisabled)){b.page=b.totalPages-1;j(e,b)}return false}); d(b.cssPageSize,f).unbind("change.pager").bind("change.pager",function(){d(b.cssPageSize,f).val(d(this).val());if(!d(this).hasClass(b.cssDisabled)){w(e,parseInt(d(this).val(),10),b);var a=d(e.tBodies[0]);a.find("tr.pagerSavedHeightSpacer").remove();d.data(e,"pagerSavedHeight",a.height());n(e,b);d.data(e,"pagerLastSize",b.size)}return false});g.unbind("disable.pager enable.pager destroy.pager").bind("disable.pager",function(){v(e,b)}).bind("enable.pager",function(){x(e,b,true)}).bind("destroy.pager", function(){v(e,b);b.container.hide();e.config.appender=null;d(e).unbind("destroy.pager sortEnd.pager enable.pager disable.pager")})})}}});d.fn.extend({tablesorterPager:d.tablesorterPager.construct})})(jQuery); +(function(d){d.extend({tablesorterPager:new function(){this.defaults={container:null,ajaxUrl:null,ajaxProcessing:function(){return[[{key:"value"}],100]},output:"{startRow} to {endRow} of {totalRows} rows",updateArrows:!0,page:0,size:10,fixedHeight:!1,removeRows:!0,cssNext:".next",cssPrev:".prev",cssFirst:".first",cssLast:".last",cssPageDisplay:".pagedisplay",cssPageSize:".pagesize",cssDisabled:"disabled",totalRows:0,totalPages:0};var h=this,i=function(c,b){var a=c.cssDisabled,e=!!b;c.updateArrows&& (c.container[c.totalRows')},l=function(c,b){var a, e=d("tr:not(."+c.config.cssChildRow+")",c.tBodies[0]),g=e.length,f=b.page*b.size,n=f+b.size;n>g&&(n=g);for(a=0;a=f&&a", {id:"tablesorterPagerLoading",width:e.outerWidth(!0),height:e.outerHeight(!0)}),e.before(a),d.getJSON(f,function(f){if("function"===typeof b.ajaxProcessing){var f=b.ajaxProcessing(f),r=f[0],j=r.length,m,p,q=[],k="",h="",i=d(c).addClass("hasStickyHeaders"),l=e.find("."+(c.config.widgetOptions&&c.config.widgetOptions.stickyHeaders||"tablesorter-stickyheader"));for(m=0;m";for(p in r[m])"string"===typeof p&&(0===m&&q.push(p),k+=""+r[m][p]+"");k+=""}e.find("thead tr.tablesorter-header th").each(function(b){var a= d(this),a=a.find("span").length?a.find("span:first"):a;a.html(q[b]);i&&l.length&&(a=l.find("th").eq(b),a=a.find("span").length?a.find("span:first"):a,a.html(q[b]));h+=""+q[b]+""});e.find("tfoot").html(""+h+"");g.html(k);a.remove();e.trigger("update");b.totalRows=f[1];b.totalPages=Math.ceil(b.totalRows/b.size);t(c,b);o(c,b);e.trigger("pagerChange",b)}}))},s=function(c,b,a){var e,g,f,n=d(c.tBodies[0]),h=b.length;e=a.page*a.size;var i=e+a.size;if(!(1>h)){d(c).trigger("pagerChange", a);if(a.removeRows){i>b.length&&(i=b.length);for(d(c.tBodies[0]).empty();e=a.totalPages&&(a.page=a.totalPages-1,j(c,a));t(c,a);a.isDisabled||o(c,a)}},w=function(c,b){b.ajax?i(b,!0):(b.isDisabled=!0,d.data(c,"pagerLastPage",b.page),d.data(c,"pagerLastSize",b.size),b.page=0,b.size=b.totalRows,b.totalPages=1,d("tr.pagerSavedHeightSpacer",c.tBodies[0]).remove(),s(c,c.config.rowsCopy,b));d(b.cssPageSize, b.container).addClass(b.cssDisabled)[0].disabled=!0},j=function(c,b){if(!b.isDisabled){if(0>b.page||b.page>b.totalPages-1)b.page=0;d.data(c,"pagerLastPage",b.page);b.ajax?v(c,b):s(c,c.config.rowsCopy,b)}},x=function(c,b,a){a.size=b;d.data(c,"pagerLastPage",a.page);d.data(c,"pagerLastSize",a.size);a.totalPages=Math.ceil(a.totalRows/a.size);j(c,a)},y=function(c,b,a){var e=d(b.cssPageSize,b.container).removeClass(b.cssDisabled).removeAttr("disabled");b.isDisabled=!1;b.page=d.data(c,"pagerLastPage")|| 0;b.size=d.data(c,"pagerLastSize")||parseInt(e.val(),10);b.totalPages=Math.ceil(b.totalRows/b.size);a&&(d("table").trigger("update"),x(c,b.size,b),u(c,b),o(c,b))};h.appender=function(c,b){var a=c.config.pager;a.ajax||(c.config.rowsCopy=b,a.totalRows=b.length,a.size=d.data(c,"pagerLastSize")||a.size,a.totalPages=Math.ceil(a.totalRows/a.size),s(c,b,a))};h.construct=function(c){return this.each(function(){var b=this.config,a=b.pager=d.extend({},d.tablesorterPager.defaults,c),e=this,g=d(e),f=d(a.container).show(); b.appender=h.appender;y(e,a,!1);"string"===typeof a.ajaxUrl?(a.ajax=!0,v(e,a)):(a.ajax=!1,d(this).trigger("appendCache"),u(e,a));d(a.cssFirst,f).unbind("click.pager").bind("click.pager",function(){if(!d(this).hasClass(a.cssDisabled)){a.page=0;j(e,a)}return false});d(a.cssNext,f).unbind("click.pager").bind("click.pager",function(){if(!d(this).hasClass(a.cssDisabled)){a.page++;if(a.page>=a.totalPages-1)a.page=a.totalPages-1;j(e,a)}return false});d(a.cssPrev,f).unbind("click.pager").bind("click.pager", function(){if(!d(this).hasClass(a.cssDisabled)){a.page--;if(a.page<=0)a.page=0;j(e,a)}return false});d(a.cssLast,f).unbind("click.pager").bind("click.pager",function(){if(!d(this).hasClass(a.cssDisabled)){a.page=a.totalPages-1;j(e,a)}return false});d(a.cssPageSize,f).unbind("change.pager").bind("change.pager",function(){d(a.cssPageSize,f).val(d(this).val());if(!d(this).hasClass(a.cssDisabled)){x(e,parseInt(d(this).val(),10),a);var b=d(e.tBodies[0]);b.find("tr.pagerSavedHeightSpacer").remove();d.data(e, "pagerSavedHeight",b.height());o(e,a);d.data(e,"pagerLastSize",a.size)}return false});g.unbind("disable.pager enable.pager destroy.pager").bind("disable.pager",function(){w(e,a)}).bind("enable.pager",function(){y(e,a,true)}).bind("destroy.pager",function(){w(e,a);a.container.hide();e.config.appender=null;d(e).unbind("destroy.pager sortEnd.pager enable.pager disable.pager")})})}}});d.fn.extend({tablesorterPager:d.tablesorterPager.construct})})(jQuery); diff --git a/docs/example-pager-ajax.html b/docs/example-pager-ajax.html index 11c5f5f4..6e1ff314 100644 --- a/docs/example-pager-ajax.html +++ b/docs/example-pager-ajax.html @@ -21,7 +21,33 @@ -