From 16c2108cd09443d84918def4e625ff4ee0b911ca Mon Sep 17 00:00:00 2001 From: Rob Garrison Date: Tue, 6 Dec 2011 09:25:51 -0600 Subject: [PATCH] stickyheaders scroll left now --- README.markdown | 4 ++++ changelog.txt | 5 +++++ js/jquery.tablesorter.widgets.js | 22 ++++++++++++++-------- js/jquery.tablesorter.widgets.min.js | 15 ++++++++------- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/README.markdown b/README.markdown index 0ec91c37..dd0fece5 100644 --- a/README.markdown +++ b/README.markdown @@ -34,6 +34,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.4 (2011-12-6) + +* Updated the sticky header widget to reposition the sticky header when scrolling left. Fix for [issue #9](https://github.com/Mottie/tablesorter/issues/9). + #### Version 2.0.23.3 (2011-11-7) * Updated the filter widget: diff --git a/changelog.txt b/changelog.txt index 00cce968..a360c671 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,10 @@ TableSorter Change Log +Version 2.0.23.4 (2011-12-6) +============================ + +* Updated the sticky header widget to reposition the sticky header when scrolling left. Fix for [issue #9](https://github.com/Mottie/tablesorter/issues/9). + Version 2.0.23.3 (2011-11-7) ============================ diff --git a/js/jquery.tablesorter.widgets.js b/js/jquery.tablesorter.widgets.js index 39d7b1b1..1942c1ad 100644 --- a/js/jquery.tablesorter.widgets.js +++ b/js/jquery.tablesorter.widgets.js @@ -1,4 +1,4 @@ -/* TableSorter 2.0 Widgets - updated 11/7/2011 +/* TableSorter 2.0 Widgets - updated 12/6/2011 * * jQuery UI Theme * Column Styles @@ -154,7 +154,8 @@ $.tablesorter.addWidget({ id: "stickyHeaders", format: function(table) { if ($(table).find('.stickyHeader').length) { return; } - var win = $(window), + var $table = $(table), + win = $(window), header = $(table).find('thead'), hdrCells = header.find('tr').children(), brdr = parseInt(hdrCells.eq(0).css('border-left-width'),10), @@ -170,7 +171,7 @@ $.tablesorter.addWidget({ }), stkyCells = sticky.children(); // update sticky header class names to match real header - $(table).bind('sortEnd', function(e,t){ + $table.bind('sortEnd', function(e,t){ var th = $(t).find('thead tr'), sh = th.filter('.stickyHeader').children(); th.filter(':not(.stickyHeader)').children().each(function(i){ @@ -197,14 +198,19 @@ $.tablesorter.addWidget({ // make it sticky! win .scroll(function(){ - var $t = $(table), - offset = $t.offset(), + var offset = $table.offset(), sTop = win.scrollTop(), - vis = ((sTop > offset.top) && (sTop < offset.top + $t.find('tbody').height())) ? 'visible' : 'hidden'; - sticky.css('visibility', vis); + vis = ((sTop > offset.top) && (sTop < offset.top + $table.find('tbody').height())) ? 'visible' : 'hidden'; + sticky.css({ + left : offset.left - win.scrollLeft(), + visibility : vis + }); }) .resize(function(){ - sticky.css({ width: header.outerWidth() + brdr * 2 }); + sticky.css({ + left : $(table).offset().left - win.scrollLeft(), + width: header.outerWidth() + brdr * 2 + }); stkyCells.each(function(i){ $(this).width( hdrCells.eq(i).width() ); }); diff --git a/js/jquery.tablesorter.widgets.min.js b/js/jquery.tablesorter.widgets.min.js index 6789b2ea..e7532192 100644 --- a/js/jquery.tablesorter.widgets.min.js +++ b/js/jquery.tablesorter.widgets.min.js @@ -1,8 +1,9 @@ -/* TableSorter 2.0 Widgets - updated 11/7/2011 */ -(function(c){ -c.tablesorter.addWidget({id:"uitheme",format:function(f){var b,a,g,e=f.config,d=["ui-icon-arrowthick-2-n-s","ui-icon-arrowthick-1-s","ui-icon-arrowthick-1-n"];e.widgetUitheme&&e.widgetUitheme.hasOwnProperty("css")&&(d=e.widgetUitheme.css||d);g=d.join(" ");e.debug&&(b=new Date);c(f).is(".ui-theme")||(c(f).addClass("ui-widget ui-widget-content ui-corner-all ui-theme"),c.each(e.headerList,function(){c(this).addClass("ui-widget-header ui-corner-all").append('').hover(function(){c(this).addClass("ui-state-hover")}, function(){c(this).removeClass("ui-state-hover")})}));c.each(e.headerList,function(b){e.headers[b]&&e.headers[b].sorter===false?c(this).find("span.ui-icon").removeClass(g+" ui-icon"):(a=c(this).is("."+e.cssAsc)?d[1]:c(this).is("."+e.cssDesc)?d[2]:c(this).is("."+e.cssHeader)?d[0]:"",c(this)[a===d[0]?"removeClass":"addClass"]("ui-state-active").find("span.ui-icon").removeClass(g).addClass(a))});e.debug&&c.tablesorter.benchmark("Applying uitheme widget",b)}}); -c.tablesorter.addWidget({id:"columns",format:function(f){var b, a,g,e,d=f.config,i=d.sortList,h=i.length,j=["primary","secondary","tertiary"];d.widgetColumns&&d.widgetColumns.hasOwnProperty("css")&&(j=d.widgetColumns.css||j);g=j.length-1;e=j.join(" ");d.debug&&(a=new Date);i&&i[0]&&c("tr:visible",f.tBodies[0]).each(function(a){b=c(this).children().removeClass(e);b.eq(i[0][0]).addClass(j[0]);if(h>1)for(a=1;a',l;h.debug&&(l=new Date);for(b=0;b';k.find("thead").append(f+="").find(".filter").bind("keyup",function(){a=k.find(".filter").map(function(){return(c(this).val()||"").toLowerCase()}).get();a.join("")===""?k.find("tr").show(): k.find("tbody").find("tr:not(.expand-child)").each(function(){g=true;d=c(this).nextUntil("tr:not(.expand-child)");e=d.length&&(typeof h.widgetFilterChildRows!=="undefined"?h.widgetFilterChildRows:1)?d.text():"";i=c(this).find("td");for(b=0;b=0?g=g?true:false:a[b]!==""&&(g=false);c(this)[g?"show":"hide"]();if(d.length)d[g?"show":"hide"]()});k.trigger("applyWidgets")});h.filtering=true;h.debug&&c.tablesorter.benchmark("Applying Filter widget", l)}}}); -c.tablesorter.addWidget({id:"stickyHeaders",format:function(f){if(!c(f).find(".stickyHeader").length){var b=c(window),a=c(f).find("thead"),g=a.find("tr").children(),e=parseInt(g.eq(0).css("border-left-width"),10),d=a.find("tr").clone().addClass("stickyHeader").css({width:a.outerWidth()+e*2,position:"fixed",top:0,marginLeft:-e,visibility:"hidden",zIndex:10}),i=d.children();c(f).bind("sortEnd",function(a,b){var d=c(b).find("thead tr"),f=d.filter(".stickyHeader").children();d.filter(":not(.stickyHeader)").children().each(function(a){f.eq(a).attr("class", c(this).attr("class"))})});g.each(function(a){var b=c(this);i.eq(a).width(b.width()).bind("click",function(a){b.trigger(a)}).bind("mousedown",function(){this.onselectstart=function(){return false};return false})});a.prepend(d);b.scroll(function(){var a=c(f),e=a.offset(),g=b.scrollTop(),a=g>e.top&&g').wrapInner('
').find(".resizer").bind("mousedown",function(b){a.resizable_target= c(b.target).closest("th");a.resizable_position=b.pageX}).end().bind("mousemove",function(c){if(!(a.resizable_position===0||typeof a.resizable_target===null)){var b=c.pageX-a.resizable_position,d=a.resizable_target.closest("th").prev();if(!(a.resizable_target.width()<-b||d&&d.width()<=b))d.width(d.width()+b),a.resizable_position=c.pageX}}).bind("mouseup",function(){d();return false});c(f).find("thead").bind("mouseup mouseleave",function(){d()});a.resizable=true}}}) +/* TableSorter 2.0 Widgets - updated 12/6/2011 */ + +(function(a){ +a.tablesorter.addWidget({id:"uitheme",format:function(d){var c,b,g,f=d.config,e=["ui-icon-arrowthick-2-n-s","ui-icon-arrowthick-1-s","ui-icon-arrowthick-1-n"];f.widgetUitheme&&f.widgetUitheme.hasOwnProperty("css")&&(e=f.widgetUitheme.css||e);g=e.join(" ");f.debug&&(c=new Date);a(d).is(".ui-theme")||(a(d).addClass("ui-widget ui-widget-content ui-corner-all ui-theme"),a.each(f.headerList,function(){a(this).addClass("ui-widget-header ui-corner-all").append('').hover(function(){a(this).addClass("ui-state-hover")}, function(){a(this).removeClass("ui-state-hover")})}));a.each(f.headerList,function(c){f.headers[c]&&!1===f.headers[c].sorter?a(this).find("span.ui-icon").removeClass(g+" ui-icon"):(b=a(this).is("."+f.cssAsc)?e[1]:a(this).is("."+f.cssDesc)?e[2]:a(this).is("."+f.cssHeader)?e[0]:"",a(this)[b===e[0]?"removeClass":"addClass"]("ui-state-active").find("span.ui-icon").removeClass(g).addClass(b))});f.debug&&a.tablesorter.benchmark("Applying uitheme widget",c)}}); +a.tablesorter.addWidget({id:"columns",format:function(d){var c, b,g,f,e=d.config,i=e.sortList,h=i.length,j=["primary","secondary","tertiary"];e.widgetColumns&&e.widgetColumns.hasOwnProperty("css")&&(j=e.widgetColumns.css||j);g=j.length-1;f=j.join(" ");e.debug&&(b=new Date);i&&i[0]&&a("tr:visible",d.tBodies[0]).each(function(b){c=a(this).children().removeClass(f);c.eq(i[0][0]).addClass(j[0]);if(1',l;h.debug&&(l=new Date);for(c=0;c';k.find("thead").append(d+="").find(".filter").bind("keyup",function(){b=k.find(".filter").map(function(){return(a(this).val()||"").toLowerCase()}).get();""===b.join("")?k.find("tr").show(): k.find("tbody").find("tr:not(.expand-child)").each(function(){g=!0;e=a(this).nextUntil("tr:not(.expand-child)");f=e.length&&("undefined"!==typeof h.widgetFilterChildRows?h.widgetFilterChildRows:1)?e.text():"";i=a(this).find("td");for(c=0;ca.top&&d').wrapInner('
').find(".resizer").bind("mousedown", function(c){b.resizable_target=a(c.target).closest("th");b.resizable_position=c.pageX}).end().bind("mousemove",function(a){if(!(0===b.resizable_position||null===typeof b.resizable_target)){var c=a.pageX-b.resizable_position,d=b.resizable_target.closest("th").prev();if(!(b.resizable_target.width()<-c||d&&d.width()<=c))d.width(d.width()+c),b.resizable_position=a.pageX}}).bind("mouseup",function(){e();return!1});a(d).find("thead").bind("mouseup mouseleave",function(){e()});b.resizable=!0}}}) })(jQuery); \ No newline at end of file