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

[data grid] Columns selection component losing anchorElement/scroll state #13436

Closed
russ0133 opened this issue Jun 10, 2024 · 5 comments
Closed
Labels
component: data grid This is the name of the generic UI component, not the React module! customization: extend Logic customizability feature: Column visibility support: commercial Support request from paid users support: premium standard Support request from a Premium standard plan user. https://mui.com/legal/technical-support-sla/

Comments

@russ0133
Copy link

russ0133 commented Jun 10, 2024

The problem in depth

We are running everything on server side (filtering, hiding etc) and we have a custom toolbar component and a custom columnsPanel component. We have been going through an issue for quite some time where (I assume) when the data (rows, columns) state is re-rendered (for example, when hiding a column or reordering columns) the columnsPanel component is completely unmounted and mounted and thus leading us to lose the scroll state. (that on x-data-grid v5.17.26)

This was an issue which we largely ignored until we upgraded x-data-grid to v7.5.0 and now we not only lose the scroll state, but also the anchorEl state... I have a gut feeling that those bugs are related (or the same) and made worse in recent versions of datagrid.

Screen_Recording_2024-02-14_at_4.27.23_PM.mov
Screencast_from_2024-06-07_19-00-00.webm

Your environment

`npx @mui/envinfo`

System:
OS: Linux 6.2 Ubuntu 23.04 23.04 (Lunar Lobster)
Binaries:
Node: 18.13.0 - ~/.nvm/versions/node/v18.13.0/bin/node
npm: 9.4.0 - ~/.nvm/versions/node/v18.13.0/bin/npm
pnpm: 9.2.0 - ~/.nvm/versions/node/v18.13.0/bin/pnpm
Browsers:
Chrome: 125.0.6422.141
npmPackages:
@emotion/react: ^11.11.4 => 11.11.4
@emotion/styled: ^11.11.5 => 11.11.5
@mui/icons-material: ^5.15.16 => 5.15.18
@mui/lab: 5.0.0-alpha.170 => 5.0.0-alpha.170
@mui/material: ^5.15.16 => 5.15.18
@mui/styles: ^5.15.18 => 5.15.18
@mui/x-data-grid: ^7.5.0 => 7.5.0
@mui/x-data-grid-pro: ^7.5.0 => 7.5.0
@mui/x-date-pickers-pro: ^6.20.0 => 6.20.0
@mui/x-license: ^7.0.0 => 7.2.0
@mui/x-tree-view: ^7.6.1 => 7.6.1
@types/react: ^18.2.79 => 18.3.2
react: ^18.2.0 => 18.3.1
react-dom: ^18.2.0 => 18.3.1
typescript: ^5.4.5 => 5.4.5

Search keywords: column selection, re-render
Order ID: 91870

@russ0133 russ0133 added status: waiting for maintainer These issues haven't been looked at yet by a maintainer support: commercial Support request from paid users labels Jun 10, 2024
@michelengelen michelengelen added component: data grid This is the name of the generic UI component, not the React module! customization: extend Logic customizability feature: Column visibility support: premium standard Support request from a Premium standard plan user. https://mui.com/legal/technical-support-sla/ labels Jun 10, 2024
@michelengelen michelengelen changed the title Columns selection component losing anchorElement/scroll state [data grid] Columns selection component losing anchorElement/scroll state Jun 10, 2024
@michelengelen
Copy link
Member

Hey @russ0133 and thanks for opening an issue here.
I suspect this is due to the improvement we made on the header rendering.
Let me look into this.

@romgrk if you have any hint please feel free to comment as well! 👍🏼

@michelengelen
Copy link
Member

@russ0133 in the meantime could you try to replicate this in a minimal live code example?
It looks like you have some customization regarding the placement and content of the columns panel in place, right?

Especially helpful would be to know if you memoize the panel in some way or not!

@russ0133
Copy link
Author

@russ0133 in the meantime could you try to replicate this in a minimal live code example? It looks like you have some customization regarding the placement and content of the columns panel in place, right?

Especially helpful would be to know if you memoize the panel in some way or not!

There's no memoization. And yeah, the component itself is inside a MUI Popper and we pass the ref to the button to the columns panel component, the anchorEl being the "Columns" button in the toolbar.

I've tried setting the anchorEl without the ref and instead through slotProps in but with no success. Will try to get a minimal live code going and debug further. This seems to only happen when the server updates - if it's only on the frontend side, then it doesn't "remount" the component.

@michelengelen michelengelen added status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jun 11, 2024
@russ0133
Copy link
Author

Resolved the issue by not passing props directly to the toolbar function:

toolbar: (props) => TableToolbar({ ...props, tableId, filterButtonRef, columnPanelRef })

Instead passing the props on the slotProps in the DataGrid:

        slotProps={{
          toolbar: {
            setFilterButtonEl,
            tableId,
            filterButtonRef,.
            columnPanelRef,
          },
        }} 

Also followed this codesandbox and instead of useRef, I'm using useState

https://codesandbox.io/p/sandbox/old-forest-9dlvdd?file=%2Fsrc%2FDemo.tsx%3A12%2C31-16%2C2

@github-actions github-actions bot removed the status: waiting for author Issue with insufficient information label Jun 12, 2024
Copy link

⚠️ This issue has been closed. If you have a similar problem but not exactly the same, please open a new issue.
Now, if you have additional information related to this issue or things that could help future readers, feel free to leave a comment.

@russ0133: How did we do? Your experience with our support team matters to us. If you have a moment, please share your thoughts in this short Support Satisfaction survey.

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! customization: extend Logic customizability feature: Column visibility support: commercial Support request from paid users support: premium standard Support request from a Premium standard plan user. https://mui.com/legal/technical-support-sla/
Projects
None yet
Development

No branches or pull requests

2 participants