DataTables / FixedHeader

Fix the header, footer, left or right columns of a table in place, to always show them when scrolling
http://www.datatables.net/
Other
75 stars 83 forks source link

Calculate positions on scroll #92

Closed mcgiany closed 7 years ago

mcgiany commented 7 years ago

Hi,

In case that table has dynamic rows (for example: expanded detail row), so the table height can change dynamicaly, it is necessary to calculate positions on every scroll. If not, then can the floating header disappear when you scroll the bigger table as were at init time.

My suggestion is to change code in constructor from this:

$(window)
            .on('scroll' + this.s.namespace, function () {
                that._scroll();
            } )
            .on( 'resize'+this.s.namespace, function () {
                that.s.position.windowHeight = $(window).height();
                that.update();
            } );

to this:

$(window)
            .on('scroll' + this.s.namespace, function () {
                that._positions();
                that._scroll();
            } )
            .on( 'resize'+this.s.namespace, function () {
                that.s.position.windowHeight = $(window).height();
                that.update();
            } );

Or better, this behaviour can be changed by some options.

DataTables commented 7 years ago

Thanks for raising this. The problem with calling _positions() in the scroll event handler is that it is very slow. It has to read measurements from the DOM, which is going to seriously impact performance.

I think it would be better to call the fixedHeader.adjust() public API method whenever the table's content changes.

mcgiany commented 7 years ago

Great. That helps me a lot. Thanks :)