stickyheader widget + pager fix

This commit is contained in:
Rob Garrison 2012-01-27 14:03:41 -06:00
parent d9b791dcdb
commit 536d89280c
2 changed files with 7 additions and 5 deletions

View File

@ -1,4 +1,4 @@
/* TableSorter 2.0 Widgets - updated 12/15/2011
/* TableSorter 2.0 Widgets - updated 1/27/2012
*
* jQuery UI Theme
* Column Styles
@ -182,6 +182,8 @@ $.tablesorter.addWidget({
th.filter(':not(.stickyHeader)').children().each(function(i){
sh.eq(i).attr('class', $(this).attr('class'));
});
}).bind('pagerComplete', function(){
win.resize(); // trigger window resize to make sure column widths & position are correct
});
// set sticky header cell width and link clicks to real header
hdrCells.each(function(i){

View File

@ -1,9 +1,9 @@
/* TableSorter 2.0 Widgets - updated 12/15/2011 */
/* TableSorter 2.0 Widgets - updated 1/27/2012 */
(function(b){
b.tablesorter.addWidget({id:"uitheme",format:function(e){var c,a,g,j,h,d=e.config,f=b(e),i=["ui-icon-arrowthick-2-n-s","ui-icon-arrowthick-1-s","ui-icon-arrowthick-1-n"];d.widgetUitheme&&d.widgetUitheme.hasOwnProperty("css")&&(i=d.widgetUitheme.css||i);g=i.join(" ");d.debug&&(c=new Date);f.is(".ui-theme")||(f.addClass("ui-widget ui-widget-content ui-corner-all ui-theme"),b.each(d.headerList,function(){b(this).addClass("ui-widget-header ui-corner-all").append('<span class="ui-icon"/>').hover(function(){b(this).addClass("ui-state-hover")}, function(){b(this).removeClass("ui-state-hover")})}));b.each(d.headerList,function(c){j=b(this);this.sortDisabled?j.find("span.ui-icon").removeClass(g+" ui-icon"):(a=j.hasClass(d.cssAsc)?i[1]:j.hasClass(d.cssDesc)?i[2]:j.hasClass(d.cssHeader)?i[0]:"",h=f.hasClass("hasStickyHeaders")?f.find("tr.stickyHeader").find("th").eq(c).add(j):j,h[a===i[0]?"removeClass":"addClass"]("ui-state-active").find("span.ui-icon").removeClass(g).addClass(a))});d.debug&&b.tablesorter.benchmark("Applying uitheme widget", c)}});
b.tablesorter.addWidget({id:"columns",format:function(e){var c,a,g,j,h=e.config,d=h.sortList,f=d.length,i=["primary","secondary","tertiary"];h.widgetColumns&&h.widgetColumns.hasOwnProperty("css")&&(i=h.widgetColumns.css||i);g=i.length-1;j=i.join(" ");h.debug&&(a=new Date);d&&d[0]&&b("tr:visible",e.tBodies[0]).each(function(a){c=b(this).children().removeClass(j);c.eq(d[0][0]).addClass(i[0]);if(1<f)for(a=1;a<f;a++)c.eq(d[a][0]).addClass(i[a]||i[g])});h.debug&&b.tablesorter.benchmark("Applying Columns widget", a)}});
b.tablesorter.addWidget({id:"filter",format:function(e){if(!e.config.filtering){var c,a,g,j,h,d,f=e.config,i=f.headerList.length,k=b(e),e='<tr class="filters">',l;f.debug&&(l=new Date);for(c=0;c<i;c++)e+='<td><input type="text" class="filter" data-col="'+c+'" style="',e+=f.headers[c]&&"filter"in f.headers[c]&&!1===f.headers[c].filter||b(f.headerList[c]).is(".filter-false")?"display:none":"",e+='"></td>';k.find("thead").append(e+="</tr>").find(".filter").bind("keyup",function(){a=k.find(".filter").map(function(){return(b(this).val()|| "").toLowerCase()}).get();""===a.join("")?k.find("tr").show():k.find("tbody").find("tr:not(.expand-child)").each(function(){g=!0;h=b(this).nextUntil("tr:not(.expand-child)");j=h.length&&("undefined"!==typeof f.widgetFilterChildRows?f.widgetFilterChildRows:1)?h.text():"";d=b(this).find("td");for(c=0;c<i;c++)""!==a[c]&&0<=(d.eq(c).text()+j).toLowerCase().indexOf(a[c])?g=g?!0:!1:""!==a[c]&&(g=!1);b(this)[g?"show":"hide"]();if(h.length)h[g?"show":"hide"]()});k.trigger("applyWidgets")});f.filtering=!0; f.debug&&b.tablesorter.benchmark("Applying Filter widget",l)}}});
b.tablesorter.addWidget({id:"stickyHeaders",format:function(e){if(!b(e).hasClass("hasStickyHeaders")){var c=b(e).addClass("hasStickyHeaders"),a=b(window),g=b(e).find("thead"),j=g.find("tr").children(),h=j.eq(0),d=parseInt(j.eq(0).css("border-left-width"),10),f=g.find("tr:not(.filters)").clone().addClass("stickyHeader").css({width:g.outerWidth()+2*d,position:"fixed",left:h.offset().left,marginLeft:-d,top:0,visibility:"hidden",zIndex:10}), i=f.children(),k;c.bind("sortEnd",function(a,c){var d=b(c).find("thead tr"),f=d.filter(".stickyHeader").children();d.filter(":not(.stickyHeader)").children().each(function(a){f.eq(a).attr("class",b(this).attr("class"))})});j.each(function(a){var c=b(this);i.eq(a).width(c.width()).bind("click",function(a){c.trigger(a)}).bind("mousedown",function(){this.onselectstart=function(){return!1};return!1})});g.prepend(f);a.scroll(function(){var b=h.offset(),d=a.scrollTop(),d=d>b.top&&d<b.top+c.find("tbody").height()? "visible":"hidden";f.css({left:b.left-a.scrollLeft(),visibility:d});d!==k&&(a.resize(),k=d)}).resize(function(){f.css({left:h.offset().left-a.scrollLeft(),width:g.outerWidth()+2*d});i.each(function(a){b(this).width(j.eq(a).width())})})}}});
b.tablesorter.addWidget({id:"resizable",format:function(e){if(!e.config.resizable){var c,a=e.config,g=a.headerList,j=g.length,h=function(){a.resizable_position=0;a.resizable_target=null;b(window).trigger("resize")};a.resizable_target=null;a.resizable_position=0; for(c=1;c<j;c++)b(g[c]).append('<div class="resizer" style="cursor:w-resize;position:absolute;height:100%;width:20px;left:-20px;top:0;z-index:1;"></div>').wrapInner('<div style="position:relative;height:100%;width:100%"></div>').find(".resizer").bind("mousedown",function(d){a.resizable_target=b(d.target).closest("th");a.resizable_position=d.pageX}).end().bind("mousemove",function(b){if(!(0===a.resizable_position||null===typeof a.resizable_target)){var c=b.pageX-a.resizable_position,e=a.resizable_target.closest("th").prev(); if(!(a.resizable_target.width()<-c||e&&e.width()<=c))e.width(e.width()+c),a.resizable_position=b.pageX}}).bind("mouseup",function(){h();return!1});b(e).find("thead").bind("mouseup mouseleave",function(){h()});a.resizable=!0}}})
b.tablesorter.addWidget({id:"stickyHeaders",format:function(e){if(!b(e).hasClass("hasStickyHeaders")){var c=b(e).addClass("hasStickyHeaders"),a=b(window),g=b(e).find("thead"),j=g.find("tr").children(),h=j.eq(0),d=parseInt(j.eq(0).css("border-left-width"),10),f=g.find("tr:not(.filters)").clone().addClass("stickyHeader").css({width:g.outerWidth()+2*d,position:"fixed",left:h.offset().left,marginLeft:-d,top:0,visibility:"hidden",zIndex:10}), i=f.children(),k;c.bind("sortEnd",function(a,c){var d=b(c).find("thead tr"),f=d.filter(".stickyHeader").children();d.filter(":not(.stickyHeader)").children().each(function(a){f.eq(a).attr("class",b(this).attr("class"))})}).bind("pagerComplete",function(){a.resize()});j.each(function(a){var c=b(this);i.eq(a).width(c.width()).bind("click",function(a){c.trigger(a)}).bind("mousedown",function(){this.onselectstart=function(){return!1};return!1})});g.prepend(f);a.scroll(function(){var b=h.offset(),d=a.scrollTop(), d=d>b.top&&d<b.top+c.find("tbody").height()?"visible":"hidden";f.css({left:b.left-a.scrollLeft(),visibility:d});d!==k&&(a.resize(),k=d)}).resize(function(){f.css({left:h.offset().left-a.scrollLeft(),width:g.outerWidth()+2*d});i.each(function(a){b(this).width(j.eq(a).width())})})}}});
b.tablesorter.addWidget({id:"resizable",format:function(e){if(!e.config.resizable){var c,a=e.config,g=a.headerList,j=g.length,h=function(){a.resizable_position=0;a.resizable_target=null;b(window).trigger("resize")};a.resizable_target= null;a.resizable_position=0;for(c=1;c<j;c++)b(g[c]).append('<div class="resizer" style="cursor:w-resize;position:absolute;height:100%;width:20px;left:-20px;top:0;z-index:1;"></div>').wrapInner('<div style="position:relative;height:100%;width:100%"></div>').find(".resizer").bind("mousedown",function(d){a.resizable_target=b(d.target).closest("th");a.resizable_position=d.pageX}).end().bind("mousemove",function(b){if(!(0===a.resizable_position||null===typeof a.resizable_target)){var c=b.pageX-a.resizable_position, e=a.resizable_target.closest("th").prev();if(!(a.resizable_target.width()<-c||e&&e.width()<=c))e.width(e.width()+c),a.resizable_position=b.pageX}}).bind("mouseup",function(){h();return!1});b(e).find("thead").bind("mouseup mouseleave",function(){h()});a.resizable=!0}}})
})(jQuery);