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.92k stars 1.19k forks source link

[data grid] Entering in edit mode, reload column configuration #12429

Open GeoffreyHervet opened 3 months ago

GeoffreyHervet commented 3 months ago

Steps to reproduce

Link to live example: (required)

  1. Resize the width of the Name column
  2. Enter in edit mode in a row

https://github.com/mui/mui-x/assets/617780/1a0c3d63-b152-4eec-8725-34f498903002

Current behavior

When you resize a column (or even you reorder the columns), then you enter in edit mode, you lost the width of the column.

Expected behavior

The column width should not be updated.

Context

If a useMemo is used for the column definition, it won't fix the issue, you will have a issue in the action column. getActions won't have the right value of rowModesModel. If in the useMemo, you give rowModesModel as a dependency, you will have the same issue ...

Your environment

{
  "name": "vrwhkv--run",
  "version": "0.0.0",
  "private": true,
  "dependencies": {
    "@emotion/react": "11.11.4",
    "@emotion/styled": "11.11.0",
    "@mui/icons-material": "5.15.12",
    "@mui/material": "5.15.12",
    "@mui/system": "^5.4.1",
    "@mui/x-data-grid": "6.19.6",
    "@mui/x-data-grid-generator": "6.19.6",
    "@mui/x-data-grid-pro": "^6.19.6",
    "@types/react": "18.2.65",
    "@types/react-dom": "18.2.21",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "typescript": "5.4.2"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  },
  "devDependencies": {
    "react-scripts": "latest"
  }
}

Search keywords: datagrid edit resize Order ID: Not provided

cherniavskii commented 3 months ago

This is a tricky one. You're right about the useMemo - it's not going to change anything because the columns would be instantiated on dependencies change anyway.

To solve this issue, we need to somehow pass things to the actions cells without creating columns during render. I'll think about this.

romgrk commented 3 months ago

Is there any issue beyond column width? We could maintain a column width cache to avoid resetting it. Not elegant at all, but column width is kinda special as it can be changed by the end-user without going through the columns prop.

cherniavskii commented 3 months ago

Is there any issue beyond column width?

Yes, column ordering. Maintaining the column sizes and order makes sense to me. If users need to reset the columns – they can force it by changing the key on the data grid.

GeoffreyHervet commented 2 months ago

Hello,

Does the label support:commercial means the ticket is prioritized and the issue will be fixed ?

Thanks

roveri-softwares commented 1 month ago

Hello,

I have the same workaround.

Thanks