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

[question] Using scrollToIndexes() together with pagination #15179

Open
santileortiz opened this issue Oct 29, 2024 · 2 comments
Open

[question] Using scrollToIndexes() together with pagination #15179

santileortiz opened this issue Oct 29, 2024 · 2 comments
Labels
component: data grid This is the name of the generic UI component, not the React module! support: commercial Support request from paid users support: pro standard Support request from a Pro standard plan user. https://mui.com/legal/technical-support-sla/

Comments

@santileortiz
Copy link

santileortiz commented Oct 29, 2024

The problem in depth

As I understand from #6290 scrollToIndexes() is not supposed to switch pages automatically, so we're supposed to do this by hand. Still, the only way I've managed to make it work on all cases is by wrapping the call to the API into a setTimeout(), which doesn't feel correct.

You can see the attempt in the following sandbox: https://codesandbox.io/p/sandbox/serene-wood-t5xdpl

It almost works, except when going from the last page (which is not a full page, has 25 rows while the page size is 50), to the last row in the other pages. In other words, try going to row 101 (or 125) then to row 50 (or 100), for these cases the page change happens, but the scrolling doesn't work.

The delay that fixes the problem is commented out, but we would like to have a solution that doesn't depend on it. Seems like computation of the scroll position happens based on the current viewport and not the target one, and because the last page is shorter, it fails. We have not found a way to ensure the scroll computation happens after the page switch, other than using the delay.

Your environment

Version 7.21.0 from the sandbox.

Search keywords: scrollToIndexes, pagination
Order ID: 93242

@santileortiz santileortiz added status: waiting for maintainer These issues haven't been looked at yet by a maintainer support: commercial Support request from paid users labels Oct 29, 2024
@github-actions github-actions bot added component: data grid This is the name of the generic UI component, not the React module! support: pro standard Support request from a Pro standard plan user. https://mui.com/legal/technical-support-sla/ labels Oct 29, 2024
@michelengelen
Copy link
Member

Hey @santileortiz ... I'll have a look into this tomorrow. 👍🏼

@michelengelen
Copy link
Member

Hey @santileortiz and sry for the late reply ... I got sick and couldn't answer in time as promised.

The problem is basically found here:

const handlePaginationModelChange: GridEventListener<'paginationModelChange'> = () => {
const paginationModel = gridPaginationModelSelector(apiRef);
if (apiRef.current.virtualScrollerRef?.current) {
apiRef.current.scrollToIndexes({
rowIndex: paginationModel.page * paginationModel.pageSize,
});
}
};

We do this to ensure we show the top of the rows on every page change, even if the previous scroll was showing the last row. So, as of now you would need to wrap the scrollToIndexes call in a setTimeout as you did before.

I'll add this issue to the board and ask the team though if there is a way we can alter the paginationModel scrolling behavior to support such a use-case.

@github-project-automation github-project-automation bot moved this to 🆕 Needs refinement in MUI X Data Grid Nov 4, 2024
@michelengelen michelengelen removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Nov 4, 2024
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! support: commercial Support request from paid users support: pro standard Support request from a Pro standard plan user. https://mui.com/legal/technical-support-sla/
Projects
Status: 🆕 Needs refinement
Development

No branches or pull requests

2 participants