Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I ended up reverse engineering how google was accomplishing the top header. They were creating a copy of the entire table, putting it in a div, absolutely positioning it and setting a height equal to the height of the first row. That accomplishes the effect that when you scroll down the main table it stays fixed at the top.</p> <p>Side-scrolling is more complicated, because when side-scrolling they need the header to also scroll. CSS doesn't have a mechanism for this (since it's absolutely positioned outside of what's scrolling), so Google's using javascript here.</p> <p>To emulate this behavior for a fixed column, we first make a third clone of the table. Then we go through some CSS gymnastics to get the width/height &amp; position correct. Finally, we attach a listener to the onScroll event of the main table that scrolls the header table in unison. The $.schollbarWidth() function comes from <a href="http://benalman.com/projects/jquery-misc-plugins/#scrollbarwidth" rel="noreferrer">this plugin</a>.</p> <pre><code>visualization = new google.visualization.Table(document.getElementById('table')); visualization.draw(data); var fullTable = $('#table &gt; div &gt; div:first'); var yHeader = fullTable.clone().insertAfter(fullTable); yHeader.css('width', yHeader.children('tr td:first').outerWidth()) .css('height', fullTable.innerHeight() - $.scrollbarWidth()) .css('position', 'absolute') .css('top', '0px') .css('left', '0px') .css('overflow', 'hidden') fullTable.scroll(function() { yHeader.scrollTop(fullTable.scrollTop()); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload