Skip to content
This repository has been archived by the owner on Nov 2, 2021. It is now read-only.

Stick the table headings to the top while scrolling down #2434

Open
Sayan-Nandy opened this issue Apr 24, 2021 · 11 comments · May be fixed by #2551
Open

Stick the table headings to the top while scrolling down #2434

Sayan-Nandy opened this issue Apr 24, 2021 · 11 comments · May be fixed by #2551
Assignees
Labels
Status: Claimed It's clear what the subject of the issue is about, and what the resolution should be

Comments

@Sayan-Nandy
Copy link

I can't remember which column stands for what when I scroll down, so it might be helpful to stick the table headers to the top when scrolling down. This is especially helpful in mobiles.
Screenshot_20210424_123957

@KANE-99
Copy link

KANE-99 commented May 18, 2021

/claim

@shuklaayush
Copy link
Member

/available

@github-actions github-actions bot added Status: Available Reply with /claim to assign to you and removed Status: Review Needed labels Jun 5, 2021
@github-actions
Copy link

github-actions bot commented Jun 5, 2021

This issue is available for contribution.

Please reply "/claim" (without quotes) if you wish to work on this issue.

@singharyan1007
Copy link

/claim

@github-actions github-actions bot added Status: Claimed It's clear what the subject of the issue is about, and what the resolution should be and removed Status: Available Reply with /claim to assign to you labels Jun 5, 2021
@github-actions
Copy link

github-actions bot commented Jun 5, 2021

Thank you @singharyan1007 for claiming this issue! 🎉

Please reference this issue when you submit your Pull Request and make sure you follow the contributing guidelines.

@nandirishav
Copy link

/claim

@n5r
Copy link

n5r commented Aug 17, 2021

Because of left-column being sticky we have to use JS magic for this. I don't have time to integrate in project at moment, but here's some example working code (not fully optimised, mind you):

(function(){
    // Get table and header refs
    // TODO: Make headers dynamic as table changes
    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;
        }
    });
})();

Hopefully one of the claimants can integrate in React and add a pull request :D

@sayna3311
Copy link

What is the status to this? Is this done? I would like to contribute to it.

@n5r
Copy link

n5r commented Aug 28, 2021

@sayna3311 None of the original claimants has responded, so if you can integrate the code into React it would be great!

@sayna3311
Copy link

Sure thing, you can assign it to me. Thank you.

@sayna3311
Copy link

sayna3311 commented Aug 29, 2021

@n5r @shuklaayush
I have implemented your method in react using useEffect. Here is the demo

Coronavirus.Outbreak.in.India.-.covid19india.org.-.Google.Chrome.2021-08-29.13-17-45.mp4

I'm sending the PR, please review.

@sayna3311 sayna3311 linked a pull request Aug 29, 2021 that will close this issue
4 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Status: Claimed It's clear what the subject of the issue is about, and what the resolution should be
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants