StickyTableHeaders icon indicating copy to clipboard operation
StickyTableHeaders copied to clipboard

Horizontal scroll of header does not work when scrolling table horizontally

Open idchlife opened this issue 8 years ago • 6 comments

idchlife avatar Sep 08 '16 13:09 idchlife

One solution for this is to reinit after the container the table is in scrolls. One example would be when using with the twitter-bootstrap table-responsive container.

function initSticky () {
  $('table').stickyTableHeaders();
}
$(".table-responsive").scroll(function () {
  initSticky();
});
initSticky();

In this case it would be best to do this individually per table that scrolls instead of targeting all of them where multiple tables exist on the one page.

What I haven't worked out how to solve is the headings outside the scroll region are still visible due to the fixed positioning.

brettryan avatar Oct 21 '16 03:10 brettryan

how to hide fixed header into horizontal scrollable area in responsive table?

myersultan avatar Oct 26 '16 05:10 myersultan

is there anyone who have fixed for this?

metanite avatar Dec 09 '16 07:12 metanite

Duplicate of #68.

simon04 avatar Dec 12 '16 15:12 simon04

The solution proposed here doesnt work for me as the header overflows the table, so I need to make its overflow hidden, and then it just scrolls off screen.

This is what I have done that I have working:

var lastScrollLeft = 0;
var $table =$(".table-responsive");
var $header = $table.find("thead");

$table.add($header).scroll(function() {
    var tableScrollLeft = jQuery(this).scrollLeft();
    if (lastScrollLeft != tableScrollLeft) {
        $header.scrollLeft(tableScrollLeft);
        $table.scrollLeft(tableScrollLeft);
        lastScrollLeft = tableScrollLeft;
    }
});

With this they both scroll together, even if you scroll the header on mobile rather than the table body.

ghost avatar Jan 10 '18 16:01 ghost

Here's my fix. Works really well.

$(document).ready(() => {
           $('table').stickyTableHeaders({
                       fixedOffset: $('header'),
                       scrollableArea: $('.main-container')
          });
           $('table').scroll(() => {
                       let scroll = $('table').scrollLeft();
                       $('.tableFloatingHeaderOriginal').css({ left: -scroll! });
           });
}); 

bbearche avatar Feb 23 '18 14:02 bbearche