mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
StickyHeaders: Fix dynamic updating of offset. Fixes #1412
This commit is contained in:
parent
cb420ef7d3
commit
9d27c66484
@ -1,4 +1,4 @@
|
||||
/*! Widget: stickyHeaders - updated 1/6/2017 (v2.28.4) *//*
|
||||
/*! Widget: stickyHeaders - updated 6/1/2017 (v2.28.13) *//*
|
||||
* Requires tablesorter v2.8+ and jQuery 1.4.3+
|
||||
* by Rob Garrison
|
||||
*/
|
||||
@ -55,6 +55,13 @@
|
||||
}, options.timer);
|
||||
};
|
||||
|
||||
function getStickyOffset(c, wo) {
|
||||
var $el = isNaN(wo.stickyHeaders_offset) ? $(wo.stickyHeaders_offset) : [];
|
||||
return $el.length ?
|
||||
$el.height() || 0 :
|
||||
parseInt(wo.stickyHeaders_offset, 10) || 0;
|
||||
}
|
||||
|
||||
// Sticky headers based on this awesome article:
|
||||
// http://css-tricks.com/13465-persistent-headers/
|
||||
// and https://github.com/jmosbech/StickyTableHeaders by Jonas Mosbech
|
||||
@ -91,8 +98,7 @@
|
||||
$thead = $table.children('thead:first'),
|
||||
$header = $thead.children('tr').not('.sticky-false').children(),
|
||||
$tfoot = $table.children('tfoot'),
|
||||
$stickyOffset = isNaN(wo.stickyHeaders_offset) ? $(wo.stickyHeaders_offset) : '',
|
||||
stickyOffset = $stickyOffset.length ? $stickyOffset.height() || 0 : parseInt(wo.stickyHeaders_offset, 10) || 0,
|
||||
stickyOffset = getStickyOffset(c, wo),
|
||||
// is this table nested? If so, find parent sticky header wrapper (div, not table)
|
||||
$nestedSticky = $table.parent().closest('.' + ts.css.table).hasClass('hasStickyHeaders') ?
|
||||
$table.parent().closest('table.tablesorter')[0].config.widgetOptions.$sticky.parent() : [],
|
||||
@ -114,7 +120,6 @@
|
||||
$stickyThead = $stickyTable.children('thead:first'),
|
||||
$stickyCells,
|
||||
laststate = '',
|
||||
spacing = 0,
|
||||
setWidth = function($orig, $clone){
|
||||
var index, width, border, $cell, $this,
|
||||
$cells = $orig.filter(':visible'),
|
||||
@ -146,11 +151,9 @@
|
||||
}
|
||||
},
|
||||
resizeHeader = function() {
|
||||
stickyOffset = $stickyOffset.length ? $stickyOffset.height() || 0 : parseInt(wo.stickyHeaders_offset, 10) || 0;
|
||||
spacing = 0;
|
||||
$stickyWrap.css({
|
||||
left : $attach.length ? parseInt($attach.css('padding-left'), 10) || 0 :
|
||||
$table.offset().left - parseInt($table.css('margin-left'), 10) - $xScroll.scrollLeft() - spacing,
|
||||
$table.offset().left - parseInt($table.css('margin-left'), 10) - $xScroll.scrollLeft(),
|
||||
width: $table.outerWidth()
|
||||
});
|
||||
setWidth( $table, $stickyTable );
|
||||
@ -161,6 +164,7 @@
|
||||
// Detect nested tables - fixes #724
|
||||
nestedStickyTop = $nestedSticky.length ? $nestedSticky.offset().top - $yScroll.scrollTop() + $nestedSticky.height() : 0;
|
||||
var offset = $table.offset(),
|
||||
stickyOffset = getStickyOffset(c, wo),
|
||||
yWindow = $.isWindow( $yScroll[0] ), // $.isWindow needs jQuery 1.4.3
|
||||
xWindow = $.isWindow( $xScroll[0] ),
|
||||
attachTop = $attach.length ?
|
||||
@ -176,11 +180,9 @@
|
||||
}
|
||||
if (xWindow) {
|
||||
// adjust when scrolling horizontally - fixes issue #143
|
||||
cssSettings.left = $table.offset().left - parseInt($table.css('margin-left'), 10) - $xScroll.scrollLeft() - spacing;
|
||||
}
|
||||
if ($nestedSticky.length) {
|
||||
cssSettings.top = ( cssSettings.top || 0 ) + stickyOffset + nestedStickyTop;
|
||||
cssSettings.left = $table.offset().left - parseInt($table.css('margin-left'), 10) - $xScroll.scrollLeft();
|
||||
}
|
||||
cssSettings.top = ( cssSettings.top || 0 ) + stickyOffset + nestedStickyTop;
|
||||
$stickyWrap
|
||||
.removeClass( ts.css.stickyVis + ' ' + ts.css.stickyHide )
|
||||
.addClass( isVisible === 'visible' ? ts.css.stickyVis : ts.css.stickyHide )
|
||||
|
Loading…
Reference in New Issue
Block a user