Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/components/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,43 @@ function Table({
useKeyPressEvent('?', () => {
setIsInfoVisible(!isInfoVisible);
});

useEffect(() =>{
let table = document.querySelector('.table-container>.table');
let headers = document.querySelectorAll('.table-container>.table>.row.heading:first-child>.cell');

// Set config values, set the special z indices for the header divs
const stickBottomLimit = 150;
const firstHeaderZ = 140;
const otherHeaderZ = 120;
headers.forEach((el, index)=>{
el.style.zIndex = index==0 ? firstHeaderZ : otherHeaderZ;
});

// Build the handler that makes headers stick
const handleScroll = ()=>{
const rect = table.getBoundingClientRect();
let offset = 0;
if (rect.top < 0) {
offset = Math.min(-rect.top, rect.height-stickBottomLimit);
}
headers.forEach((el)=>{
el.style.transform = 'translateY('+offset+'px)';
});
};

// Build debounced scroll listener
let ticking = false;
document.addEventListener('scroll', (e)=>{
if (!ticking) {
window.requestAnimationFrame(()=>{
handleScroll();
ticking = false;
});
ticking = true;
}
});
})

return (
<div className="Table">
Expand Down