-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[XGrid] scrollToIndexes is inconsistently scrolling rows into view #1818
Comments
Thanks for raising this issue with all these details. It might be due to a race condition 🤔 |
I spent some time investigating it yesterday - what I found was that the higher the row index, the bigger the mismatch for the scroll top. Simillar happens when you start using the keyboard to scroll the rows vertically. |
Confirmed, vertical keyboard navigation doesn't work as soon as you scroll down: #1822. |
This issue is very close to #1103. |
I'm planning to refactor this area as part of #1715, create a separate hook, something like useScrollWatch, that would do all the related scroll calculation and this method should probably go in as well. |
Related to #1911, it might even be a duplicate. |
Fixed by #2673. Here's the updated CodeSandbox using the latest beta: https://codesandbox.io/s/material-ui-x-grid-scroll-to-indexes-demo-simple-forked-lj47t?file=/src/App.tsx |
Current Behavior 😯
When selecting a row at random then scrolling to that row anytime the
selectedRow
state changes, thescrollToIndexes
method inconsistently scrolls (more like jumps) the row into view. If you look at my example and press the 'select a random row and scroll to it' button, you'll see it occasionally misses the row entirely and I need to scroll either up or down.What's interesting is it seems to produce different results with a smaller data set. I have tried replacing my ID keys in the assumption that I had shared IDs which gave me a the wrong
index
, but this didn't make a difference.I'm using
useGridAPIRef()
to access the following methods to achieve my goal:getRowIndex()
to get the row index of the row I wish to scroll togetColumnindex()
as above but for columns. I am not interested in horiztonal scrolling but it seems to be a required param for the followingscrollToIndexes()
which I understand takes a object parameter in this shape:{ rowIndex: 1, colIndex: 1 }
src: https://github.com/mui-org/material-ui-x/blob/726235cfc1510e62a2bce84c6a2b7b9ea8433589/packages/grid/_modules_/grid/models/gridCell.ts#L9scroll()
to manually scroll (sincescrollToIndexes
doesn't seem to work).I'm maybe misunderstanding how to properly scroll to any given row in the table but I was unable to find any documentation demonstrating how to do it so I had to do a bit of a deep dive into the source for
scrollToIndexes
.Expected Behavior 🤔
scrollToIndexes()
should scroll to the specified row in the table everytime, regardless of previous scroll position. The row should then be visible in the table without the user needing to scroll the table at all.Steps to Reproduce 🕹
Link: https://codesandbox.io/s/material-uix-gridscroll-to-indexes-demo-simple-bzphc
Steps:
button. this will use the out of the box
scrollToIndexes()` functionalityI have attempted to fix the problem myself by creating a similar scroll function (called
custom
). It works by takingn rows
and mulitpliying it byrowHieght
. Example:scrollPositionFromTop -= 50;
scroll({ top: scrollPositionFromTop, left: 0 });
Context 🔦
I'm trying to programatically select a row (from a separate component) and scroll the row into view to save the user from scrolling hundreds of rows to find the one they're making changes to. I have a
useEffect
which listens for the selected row ID changing (which is essentially a pointer to the row in the table for this example). When the ID changes,scrollToIndexes
fires off and should scroll the row into view for the user to see. I can select a row fine, but it's the scrolling part that is proving difficult to consistently achieve.Your Environment 🌎
`npx @material-ui/envinfo`
Order id 💳
I don't have an Order ID.
The text was updated successfully, but these errors were encountered: