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

Add Optional scrollRef prop for having manual control over tableDivContainer scroll position. #880

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

angel1254mc
Copy link

@angel1254mc angel1254mc commented Dec 7, 2024

Related Issue

None

Description

This pull request adds a new prop, scrollRef that gives users access to the ref that handles the table's vertical scroll. (when the amount of items in the table exceeds the bodies height).

Wanted to pitch this PR idea. We use this package at the company I work at and we wanted to make it so that paginating through the table always puts you at the top of the table when you switch pages. We looked for a prop or configurable parameter that would do that but couldn't find one 🥹.

I understand this prop is extremely specific to this one usecase so feel free to close MR if y'all feel it's not necessary

Related PRs

N/A

Impacted Areas in Application

material-table.js, specifically the same place where tableDivContainer gets set. Does not impact any existing functionality by itself. May cause unexpected behavior if a user tries to do something crazy with their ref.

Additional Notes

Here's an example of how this prop could be used- scrolling back to top of table body on page change.

const ExampleTable = () => {
    const scrollRef = useRef();

    return (
            <MaterialTable
                title="Table With ScrollRef"
                options={{
                    maxBodyHeight: "300px",
                    scrollRef: scrollRef,
                }}
                data={DEMO_DATA}
                columns={DEMO_COLS}
                onPageChange={() => {
                    // Scroll back to top on page change
                    if (scrollRef?.current) scrollRef.current.scrollTop = 0;
                }}
            />
    );
};

export default ExampleTable

Also removed an unused snapshot parameter in the drag-and-drop context callback but I can add that back in if need be.

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

Successfully merging this pull request may close these issues.

1 participant