mui / mui-x

MUI X: Build complex and data-rich applications using a growing list of advanced React components, like the Data Grid, Date and Time Pickers, Charts, and more!
https://mui.com/x/
3.91k stars 1.19k forks source link

[data grid] Warn when `scrollToIndexes` has invalid arguments #13578

Open oliviertassinari opened 1 week ago

oliviertassinari commented 1 week ago

Steps to reproduce

Steps:

  1. Open https://stackblitz.com/edit/mui-mui-x-87hc2f?file=src%2Fdemo.tsx,package.json
SCR-20240621-lxww
export default function ColumnAutosizingDynamicRowHeight() {
  const apiRef = useGridApiRef();
  const apiRefPro = useGridApiRefPro();

  React.useEffect(() => {
    setTimeout(() => {
      console.log('scrollToIndexes');
      apiRef.current!.scrollToIndexes({
        rowIndex: 300,
      });
      apiRefPro.current!.scrollToIndexes({
        rowIndex: 300,
      });
    }, 1000);
  }, [apiRef, apiRefPro]);

  return (
    <div style={{ height: 400, width: '100%', display: 'flex' }}>
      <div style={{ width: '50%' }}>
        Community
        <DataGrid apiRef={apiRef} rows={rows} columns={columns} />
      </div>
      <div style={{ width: '50%' }}>
        Pro
        <DataGridPro apiRef={apiRefPro} rows={rows} columns={columns} />
      </div>
    </div>
  );
}

Context

It's related to #4744, I saw this in #12242. It's probably a low priority since it works on the Pro and Premium plan. We can delegate this fix to the community.

Your environment

I can reproduce on v6.19.8 and v7.7.0

Search keywords: -

oukunan commented 1 week ago

it looks like the index does not exist on the first page of pagination, indicating that the DataGrid component's pagination is enabled by this override variable. Let's say we attempt to update rowIndex into the first page's range. It will work with scrollToIndexes in this case.

oliviertassinari commented 1 week ago

In my reproduction, we are trying to scroll to an index that isn't in the scroll container, but the grid says nothing about it.

I would expect something in that order: https://codesandbox.io/p/sandbox/auto-row-height-forked-n684rg?file=%2Fsrc%2Findex.js%3A79%2C12

SCR-20240623-lwne