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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[question] onRowsScrollEnd is never fired when initial data rows height less than table height #4184

Closed
2 tasks done
sep2 opened this issue Mar 14, 2022 · 13 comments 路 May be fixed by #8479
Closed
2 tasks done

[question] onRowsScrollEnd is never fired when initial data rows height less than table height #4184

sep2 opened this issue Mar 14, 2022 · 13 comments 路 May be fixed by #8479
Assignees
Labels
component: data grid This is the name of the generic UI component, not the React module! new feature New feature or request support: commercial Support request from paid users

Comments

@sep2
Copy link

sep2 commented Mar 14, 2022

Order ID 馃挸

#35352

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

The problem in depth 馃攳

When the page is loaded first time, I fetched some initial data rows (e.g. 10 rows), displayed them in DataGridPro. Depending on the screen size of the users, the height of these rows may or may not exceed the height of the table, therefore a scrollbar may or may not be shown.

In the case a scrollbar did show, the user can simply load more data by just scrolling down the page, which will trigger onRowsScrollEnd correctly. However in the case of a larger screen, the scrollbar did not show, so DataGridPro will not trigger onRowsScrollEnd, therefore the user has no way to load subsequent data.

I would like to implement an infinite scrolling behavior that doesn't depends on the user's screen size. That is, DataGridPro should repeadedly load the data until a scrollbar is shown. Is this possible?

Your environment 馃寧

`npx @mui/envinfo`
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.
@sep2 sep2 added status: waiting for maintainer These issues haven't been looked at yet by a maintainer support: commercial Support request from paid users labels Mar 14, 2022
@cherniavskii
Copy link
Member

Yes, I can reproduce it with static grid height: https://codesandbox.io/s/infiniteloadinggrid-material-demo-forked-fb441f?file=/demo.tsx

@cherniavskii cherniavskii added component: data grid This is the name of the generic UI component, not the React module! new feature New feature or request feature: Other and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Mar 14, 2022
@sep2
Copy link
Author

sep2 commented Mar 17, 2022

Will there be ETA for this issue? This basically makes the infinite scrolling feature unavailable.

@cherniavskii
Copy link
Member

We will look into it

@cherniavskii cherniavskii self-assigned this Mar 21, 2022
@sbitenc
Copy link

sbitenc commented Mar 28, 2022

Hi, i'm having the same issue. Any eta?

@sbitenc
Copy link

sbitenc commented Mar 28, 2022

created a temporary workaround for anyone having the same issue. It's not pretty but it works in practice.

    const ref: React.MutableRefObject<HTMLDivElement | null> = React.useRef(null);


                <div ref={ref}>
                    < Grid ....
               </ div>
    React.useEffect(() => {
        const pageHax: number = (ref?.current?.clientHeight ?? 1) / 600; // 600 is the size of initial list height in px


       // here for example, i load 10 items and they exceed the size of 600px
        if (pageHax > uniqueList.length / 10 && !PageIsLoading && uniqueList.length > 0) {
            handleOnRowsScrollEnd();
        }
    }, [uniqueList.length]);

@cherniavskii
Copy link
Member

Hey
Did you consider loading more rows initially to make sure there's enough rows on each screen size?

@sep2
Copy link
Author

sep2 commented Apr 5, 2022

This is a possible workaround, but we can't assume the screen height of our users. The best we can do for now is adding a load more button at the end and ask users to click it. Maybe we can use intersection observer to find out when the button appears in viewport, and do the loading automatically.

@cherniavskii
Copy link
Member

we can't assume the screen height of our users

By the way, why does screen size matter? Do you use vh units for grid container height?
I think initial loading of 20 rows should cover all cases?

@sep2
Copy link
Author

sep2 commented Apr 5, 2022

Yes, the grid takes full browser height.

@RobinTail
Copy link

RobinTail commented Oct 3, 2022

I'm experiencing the same issue trying to implement the infinite scrolling.
I found out that onRowsScrollEnd does not work correctly with autoHeight option.

Only when the DataGridPro if wrapped into something that has a fixed height, or an absolutely positioned and stretched to the viewport boundaries component, only in this case it works well.

@liho00
Copy link

liho00 commented Jan 6, 2023

This is a possible workaround, but we can't assume the screen height of our users. The best we can do for now is adding a load more button at the end and ask users to click it. Maybe we can use intersection observer to find out when the button appears in viewport, and do the loading automatically.

this is the proper way to achieve infinite scroll, hopefully we got this feature sooner.

I have an idea, add a slot for last row (empty div), and then we use IntersectionObserver on the last row empty div for infinitescroll. simple and precise solution

#7416 this pr can solve the infinite scroll issue, pls take a look guys!

@formatlos
Copy link

formatlos commented Mar 9, 2023

having the same issue, this also happens if the rows fit (almost )exactly ... I assume when the scrollable area is lower than thescrollEndThreshold

https://codesandbox.io/s/sleepy-farrell-uo38ju?file=/demo.tsx

@m4theushw
Copy link
Member

This one is very similar to #4371 where the discussion has evolved more. I'm closing #4184

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: data grid This is the name of the generic UI component, not the React module! new feature New feature or request support: commercial Support request from paid users
Projects
None yet
8 participants