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] Aggregated columns don't respond to changes in the "editable" property of the GridColDef #10864

Closed
JohannesByle opened this issue Oct 31, 2023 · 7 comments · Fixed by #11129
Assignees
Labels
component: data grid This is the name of the generic UI component, not the React module! feature: Aggregation Related to the data grid Aggregation feature feature: Editing Related to the data grid Editing feature plan: Premium Impact at least one Premium user regression A bug, but worse

Comments

@JohannesByle
Copy link

JohannesByle commented Oct 31, 2023

Steps to reproduce

Link to live example: (required)
https://codesandbox.io/s/cranky-carson-v8g2v7?file=/src/demo.tsx
Steps:

  1. Click the "Editable: false" button to enable editing
  2. Attempt to edit the "Unit Price" column

Current behavior

When controlling a columns editable property using a stateful value aggregated columns don't respond to changes to the value. So in the codesandbox example the editable state of the aggregated unitPrice column always reflects the initial value of the useState variable. The un-aggregated quantity column reflects the correct state.

Expected behavior

I would expect editable state of the aggregated column to reflect the state in the GridColDef. In the case of this example I would expect the unitPrice column to behave like the quantity column.

Context

I had a grid to display sub-items based on items selected in a sidebar. Some of these items are read only, others are editable. The column I was editing happened to be aggregated, and after switching to v6 I noticed that I couldn't edit the column anymore. I was able to work around the issue by placing a key on the parent component so that its state reset whenever the item changed.

Your environment

npx @mui/envinfo
  System:
    OS: Windows 10 10.0.19045
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz        
    Memory: 11.76 GB / 31.71 GB
  Binaries:
    Node: 14.18.0 - C:\Program Files\nodejs\node.EXE
    npm: 6.14.15 - C:\Program Files\nodejs\npm.CMD
  Managers:
    pip3: 23.1.2 - ~\AppData\Local\Programs\Python\Python311\Scripts\pip3.EXE
  Utilities:
    FFmpeg: 13.1.0 - C:\Program Files\ffmpeg-master-latest-win64-gpl\bin\ffmpeg.EXE
    Curl: 8.0.1 - C:\WINDOWS\system32\curl.EXE
  IDEs:
    VSCode: 1.83.1 - C:\Users\johannesbyle\AppData\Local\Programs\Microsoft VS Code\bin\code.CMD
  Languages:
    Python: 3.11.4
  Browsers:
    Chrome: 118.0.5993.118
    Edge: Spartan (44.19041.3570.0), Chromium (118.0.2088.76)
    Internet Explorer: 11.0.19041.3570

Search keywords: aggregation, editing
Order ID: 71096

@JohannesByle JohannesByle added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Oct 31, 2023
@DanailH
Copy link
Member

DanailH commented Nov 1, 2023

@JohannesByle the problem is not with the property itself but rather the way you control it. In order to change column configuration once the grid is initially loaded you need to use apiRef.current.updateColumns method. This is explained in the docs here https://mui.com/x/react-data-grid/column-definition/ (right below the first example).

@DanailH DanailH added support: question Community support but can be turned into an improvement component: data grid This is the name of the generic UI component, not the React module! 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 Nov 1, 2023
@DanailH DanailH changed the title Aggregated columns don't respond to changes in the "editable" property of the GridColDef [data grid] Aggregated columns don't respond to changes in the "editable" property of the GridColDef Nov 1, 2023
@JohannesByle
Copy link
Author

Thanks for the quick response. I had read that section of the docs, but because the two different columns behaved differently I assumed it was a bug.

In my case I have props that control whether or not a column is editable. Would the correct approach be to update the columns in a useEffect like this?

  const {editable} = props;

  useEffect(() => {
    const cols = baseCols.map((c)=> ({...c, editable}));
    apiRef.current.updateColumns(cols);
  }, [editable]);

@github-actions github-actions bot added status: waiting for maintainer These issues haven't been looked at yet by a maintainer and removed status: waiting for author Issue with insufficient information labels Nov 1, 2023
@JohannesByle
Copy link
Author

After doing further testing it looks like it's broken for the apiRef.current.updateColumns as well:
https://codesandbox.io/s/interesting-wiles-mr5vx5?file=/src/demo.tsx

@DanailH
Copy link
Member

DanailH commented Nov 2, 2023

Ah ok, I can confirm, It doesn't seem to be working.

@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 support: question Community support but can be turned into an improvement labels Nov 2, 2023
@scamden
Copy link

scamden commented Nov 17, 2023

this is a fairly huge bug.. any update on progress?

@DanailH
Copy link
Member

DanailH commented Nov 21, 2023

@scamden I've added it for today's grooming session so we can discuss and see how to proceed.

@DanailH DanailH added feature: Editing Related to the data grid Editing feature feature: Aggregation Related to the data grid Aggregation feature plan: Premium Impact at least one Premium user labels Nov 21, 2023
@cherniavskii cherniavskii self-assigned this Nov 21, 2023
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! feature: Aggregation Related to the data grid Aggregation feature feature: Editing Related to the data grid Editing feature plan: Premium Impact at least one Premium user regression A bug, but worse
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants