Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Horizontal scroll of header does not work when scrolling table horizontally #122

Open
idchlife opened this issue Sep 8, 2016 · 6 comments

Comments

@idchlife
Copy link

idchlife commented Sep 8, 2016

No description provided.

@brettryan
Copy link

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.

@myersultan
Copy link

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

@metanite
Copy link

metanite commented Dec 9, 2016

is there anyone who have fixed for this?

@simon04
Copy link
Contributor

simon04 commented Dec 12, 2016

Duplicate of #68.

@ghost
Copy link

ghost commented Jan 10, 2018

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.

@bbearche
Copy link

bbearche commented Feb 23, 2018

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! });
           });
}); 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants