Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Handling of sticky footer in relative scroll mode
  • Loading branch information
Danielku15 authored Aug 14, 2017
commit d15ec7a3889cae760971973669be4a2b4c094eec
34 changes: 26 additions & 8 deletions js/dataTables.fixedHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,13 @@ $.extend( FixedHeader.prototype, {

window.addEventListener('scroll',
function () {
if(this.c.relativeScroll) {
that._positions();
if (that.c.relativeScroll) {
that._positions();
that._scroll();
}
else {
that._scroll();
}
that._scroll();
}, true);
window.addEventListener('resize',
function () {
Expand Down Expand Up @@ -416,7 +419,6 @@ $.extend( FixedHeader.prototype, {
itemDom.placeholder.remove();
itemDom.placeholder = null;
}

this._unsize( item );

if ( item === 'header' ) {
Expand All @@ -431,6 +433,17 @@ $.extend( FixedHeader.prototype, {
itemDom.floating = null;
}
}
else if (mode === 'in-relative') {
// Remove the header from the read header and insert into a fixed
// positioned floating table clone
this._clone(item, forceChange);

itemDom.floating
.addClass('fixedHeader-locked')
.css('top', item === 'header' ? this.c[item + 'Offset'] + position.scrollParentTop : position.scrollParentTop + position.scrollParentHeight - position.tfootHeight - this.c[item + 'Offset'])
.css('left', position.left + 'px')
.css('width', position.width + 'px');
}
else if ( mode === 'in' ) {
// Remove the header from the read header and insert into a fixed
// positioned floating table clone
Expand Down Expand Up @@ -490,6 +503,7 @@ $.extend( FixedHeader.prototype, {
var position = this.s.position;
var dom = this.dom;
var tableNode = $(table.node());
var scrollParent = tableNode.scrollParent();

// Need to use the header and footer that are in the main table,
// regardless of if they are clones, since they hold the positions we
Expand All @@ -504,8 +518,9 @@ $.extend( FixedHeader.prototype, {
position.theadTop = thead.offset().top;
position.tbodyTop = tbody.offset().top;
position.theadHeight = position.tbodyTop - position.theadTop;
position.scrollParentTop = thead.scrollParent().offset().top;
position.scrollParentVisible = thead.scrollParent().is(':visible');
position.scrollParentTop = scrollParent.offset().top;
position.scrollParentVisible = scrollParent.is(':visible');
position.scrollParentHeight = scrollParent.outerHeight();

if ( tfoot.length ) {
position.tfootTop = tfoot.offset().top;
Expand Down Expand Up @@ -560,8 +575,11 @@ $.extend( FixedHeader.prototype, {
this._horizontal( 'header', windowLeft );
}

if ( this.c.footer && this.dom.tfoot.length ) {
if ( ! position.visible || windowTop + position.windowHeight >= position.tfootBottom + this.c.footerOffset ) {
if (this.c.footer && this.dom.tfoot.length) {
if (this.c.relativeScroll && position.scrollParentVisible && position.tfootTop + position.tfootHeight > position.scrollParentTop + position.scrollParentHeight ) {
footerMode = 'in-relative';
}
else if ( this.c.relativeScroll || ! position.visible || windowTop + position.windowHeight >= position.tfootBottom + this.c.footerOffset ) {
footerMode = 'in-place';
}
else if ( position.windowHeight + windowTop > position.tbodyTop + position.tfootHeight + this.c.footerOffset ) {
Expand Down