Allow possibility to define the container of a table with a fixed header (#7239)

pull/7283/head
johndoh 5 years ago committed by GitHub
parent 84505edac5
commit 81dcf4a7de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -259,12 +259,18 @@ init_header: function()
} }
}, },
/**
* Set the scrollable parent object for the table's fixed header
*/
container: window,
init_fixed_header: function() init_fixed_header: function()
{ {
var clone = $(this.list.tHead).clone(); var clone = $(this.list.tHead).clone();
if (!this.fixed_header) { if (!this.fixed_header) {
this.fixed_header = $('<table>') this.fixed_header = $('<table>')
.attr('id', this.list.id + '-fixedcopy')
.attr('class', this.list.className + ' fixedcopy') .attr('class', this.list.className + ' fixedcopy')
.attr('role', 'presentation') .attr('role', 'presentation')
.css({ position:'fixed' }) .css({ position:'fixed' })
@ -273,14 +279,14 @@ init_fixed_header: function()
$(this.list).before(this.fixed_header); $(this.list).before(this.fixed_header);
var me = this; var me = this;
$(window).resize(function() { me.resize(); }); $(window).on('resize', function() { me.resize(); });
$(window).scroll(function() { $(this.container).on('scroll', function() {
var w = $(window); var w = $(this);
me.fixed_header.css({ me.fixed_header.css({
marginLeft: -w.scrollLeft() + 'px', marginLeft: -w.scrollLeft() + 'px',
marginTop: -w.scrollTop() + 'px' marginTop: -w.scrollTop() + 'px'
});
}); });
});
} }
else { else {
$(this.fixed_header).find('thead').replaceWith(clone); $(this.fixed_header).find('thead').replaceWith(clone);

Loading…
Cancel
Save