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

MUI DataGrid Pro - restoreState with Column dimensions and columnVisibilityModel ignores column dimensions #11494

Open
chrisandrewsprocessunity opened this issue Dec 22, 2023 · 2 comments
Labels
bug 🐛 Something doesn't work 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/

Comments

@chrisandrewsprocessunity
Copy link

chrisandrewsprocessunity commented Dec 22, 2023

Steps to reproduce

Link to live example: (required)
https://codesandbox.io/p/sandbox/magical-bird-wj8r87?file=%2Fsrc%2FDemo.tsx

Steps:

  1. Use MUI DataGrid w/ columnVisbilityModel
  2. Using the DataGrid apiRef, use restoreState that contains both columns -> dimensions and columns -> columnVisibilityModel
  3. Note that dimensions are not applied.

Current behavior

The dimensions object is ignored when used with columnVisbilityModel

Expected behavior

All parts of the legitimate state object should be restored when using restoreState. Specifically in this case, the column dimensions should be applied/adjusted.

Context

Currently using exportState and restoreState to preserve the users state of the grid across logins and refreshes.

Your environment

npx @mui/envinfo Using Chrome

System:
OS: Windows 11 10.0.22621
Binaries:
Node: 16.12.0 - C:\Program Files\nodejs\node.EXE
Yarn: Not Found
npm: 8.1.0 - C:\Program Files\nodejs\npm.CMD
Browsers:
Chrome: Not Found
Edge: Chromium (120.0.2210.77)
npmPackages:
@emotion/react: 11.10.5
@emotion/styled: 11.10.5
@mui/base: 5.0.0-alpha.110
@mui/core-downloads-tracker: 5.11.2
@mui/icons-material: 5.11.0
@mui/lab: 5.0.0-alpha.112
@mui/material: 5.11.2
@mui/private-theming: 5.11.2
@mui/styled-engine: 5.11.0
@mui/styles: 5.11.2
@mui/system: 5.11.2
@mui/types: 7.2.3
@mui/utils: 5.14.18
@mui/x-data-grid: 6.18.5
@mui/x-data-grid-pro: 6.18.5
@mui/x-date-pickers: 5.0.12
@mui/x-date-pickers-pro: 5.0.12
@mui/x-license-pro: 5.17.12
@types/react: 18.0.26
react: 18.2.0
react-dom: 18.2.0
typescript: 3.9.10

Search keywords: restoreState dimension columnVisbilityModel
Order ID: 65003

@chrisandrewsprocessunity chrisandrewsprocessunity added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Dec 22, 2023
@zannager zannager 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 Dec 25, 2023
@DanailH
Copy link
Member

DanailH commented Dec 29, 2023

Seems like a valid bug.

@DanailH DanailH added bug 🐛 Something doesn't work and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Dec 29, 2023
@vidup
Copy link

vidup commented Mar 19, 2024

I can reproduce (scratched our heads with a colleague on the same issue). We used to save/restore automatically with a wrapper around the grid. Save works, but restore does not, for views that pass a columnVisibilityModel as prop.

Here is a workaround until the issue is fixed: you can pass an initial state as a prop with the same object.

Basically something like this (from localStorage in my case):

const initialState = useMemo(() => {
  const persistedState = localStorage.getItem(`grid-${persistenceID}`);
  return {
    pagination: { paginationModel: { page: 0, pageSize: 20 } },
    pinnedColumns: {
      left: [GRID_CHECKBOX_SELECTION_COL_DEF.field],
      right: ["actions"],
    },
    ...JSON.parse(persistedState ?? "{}"),
  };
}, [persistenceID]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work 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/
Projects
None yet
Development

No branches or pull requests

4 participants