Sticky-headers: Include nested tables inside a scrolling element. Fixes #1512

This commit is contained in:
Rob Garrison 2018-02-25 12:56:41 -06:00
parent 41a550e698
commit 049fb7ca9d

View File

@ -90,7 +90,7 @@
var index, len, $t,
$table = c.$table,
// add position: relative to attach element, hopefully it won't cause trouble.
$attach = $(wo.stickyHeaders_attachTo),
$attach = $(wo.stickyHeaders_attachTo || wo.stickyHeaders_appendTo),
namespace = c.namespace + 'stickyheaders ',
// element to watch for the scroll event
$yScroll = $(wo.stickyHeaders_yScroll || wo.stickyHeaders_attachTo || window),
@ -150,7 +150,10 @@
});
}
},
getLeftPosition = function() {
getLeftPosition = function(yWindow) {
if (yWindow === false && $nestedSticky.length) {
return $table.position().left;
}
return $attach.length ?
parseInt($attach.css('padding-left'), 10) || 0 :
$table.offset().left - parseInt($table.css('margin-left'), 10) - $(window).scrollLeft();
@ -171,9 +174,11 @@
offset = $table.offset(),
stickyOffset = getStickyOffset(c, wo),
yWindow = $.isWindow( $yScroll[0] ), // $.isWindow needs jQuery 1.4.3
attachTop = $attach.length ?
( yWindow ? $yScroll.scrollTop() : $yScroll.offset().top ) :
$yScroll.scrollTop(),
yScroll = yWindow ?
$yScroll.scrollTop() :
// use parent sticky position if nested AND inside of a scrollable element - see #1512
$nestedSticky.length ? parseInt($nestedSticky[0].style.top, 10) : $yScroll.offset().top,
attachTop = $attach.length ? yScroll : $yScroll.scrollTop(),
captionHeight = wo.stickyHeaders_includeCaption ? 0 : $table.children( 'caption' ).height() || 0,
scrollTop = attachTop + stickyOffset + nestedStickyTop - captionHeight,
tableHeight = $table.height() - ($stickyWrap.height() + ($tfoot.height() || 0)) - captionHeight,
@ -187,12 +192,14 @@
cssSettings.top = yWindow ? scrollTop - $attach.offset().top : $attach.scrollTop();
}
// adjust when scrolling horizontally - fixes issue #143
tmp = getLeftPosition();
tmp = getLeftPosition(yWindow);
if (tmp !== parseInt($stickyWrap.css('left'), 10)) {
needsUpdating = true;
cssSettings.left = tmp;
}
cssSettings.top = ( cssSettings.top || 0 ) + stickyOffset + nestedStickyTop;
cssSettings.top = ( cssSettings.top || 0 ) +
// If nested AND inside of a scrollable element, only add parent sticky height
(!yWindow && $nestedSticky.length ? $nestedSticky.height() : stickyOffset + nestedStickyTop);
if (needsUpdating) {
$stickyWrap
.removeClass( ts.css.stickyVis + ' ' + ts.css.stickyHide )
@ -246,7 +253,6 @@
c.onRenderHeader.apply( $t.eq( index ), [ index, c, $stickyTable ] );
}
}
// make it sticky!
$xScroll.add($yScroll)
.unbind( ('scroll resize '.split(' ').join( namespace )).replace(/\s+/g, ' ') )