question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

<thead> displacement within a scrollable block and responsive-table bootstrap

See original GitHub issue

When using Bootstrap 3 responsive-table class it helps me when I need to scroll sideways since my table is quite large. I want to use the StickyTableHeaders so that I can know which column I am looking at, but when I scroll sideways to the right, the thead does not follow accordingly, it does not move with the table; it moves much further and leaves a large gap between it and the right side of the table.

The thead element also leaves the responsive-table div.

I call the stickyTableHeaders as follows:

$(document).ready(function()
{ 
    $("#records").tablesorter( {sortList: [[3,1]]} ); // also using TableSorter
    $('table').stickyTableHeaders({scrollableArea: $('.table-short')[0]});
}

I have some pictures of what it looks like on my Dropbox. I have not publish my site yet just for neatness sake.

As you can see below. scrollbar-2 scrollbar

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8

github_iconTop GitHub Comments

3reactions
SDKillercommented, Aug 16, 2019

This worked for me

  $('.table-responsive').on('scroll', function () {
      $(window).trigger('resize.stickyTableHeaders');
  });
2reactions
bbearchecommented, 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! });
           });
}); 
Read more comments on GitHub >

github_iconTop Results From Across the Web

Bootstrap 5 - table-responsive - not working (for me)
But this causes the vertial scroll bar (if any) to be displaced to the right of the table. Can someone point me in...
Read more >
Overflow - Bootstrap
By design, this content will vertically scroll. This is an example of using .overflow-hidden on an element with set width and height dimensions....
Read more >
Bootstrap table thead fix tbody scroll - CodePen
Adding Classes. In CodePen, whatever you write in the HTML editor is what goes within the <body> tags in a basic HTML5 template....
Read more >
Bootstrap Snippet Fixed Header Scrolling Table using HTML ...
This wont work with my code because I'm using bootsrap responsive table which has more than 40 columns and it is not working...
Read more >
Position Sticky and Table Headers | CSS-Tricks
You can't position: sticky; a <thead> . ... to sticky a parent element like the table header rather than each individual element in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found