gregnb / mui-datatables

Datatables for React using Material-UI
MIT License
2.71k stars 932 forks source link

Cannot change view column when there is a change in global state in onViewColumnsChange with setting column option to display. #1484

Open wakatakerutmt opened 4 years ago

wakatakerutmt commented 4 years ago

When I want to change global state in onViewColumnsChange function of options, I cannot change the view column of setting column option to display: 'true' or 'false'.

Expected Behavior

We can change global state in onViewColumnsChange using context and change the view column of setting column option to display: 'true' or 'false'.

Current Behavior

When we change global state in onViewColumnsChange using context , we cannot change the view column of setting column option to display: 'true' or 'false'.

Steps to Reproduce (for bugs)

Please see codesandbox ( https://codesandbox.io/s/muidatatables-custom-toolbar-forked-q257d ) and change view column in browser. aaaa

We can change "Location" column of not setting option in display, but cannot change "Name" and "Title" columns of setting option in display.

  1. make React.createContext object
  2. set provider of React.createContext object to React.useState value
  3. In child component provided the value, use MUIDatatable and React.useContext and set options to onViewColumnsChange and change the context in onViewColumnsChange and set column option to display: "true" or "display: "false"`.
  4. change view column in browser

Your Environment

Tech Version
Material-UI 4.10.2
MUI-datatables 3.2.0
React 16.9.0
browser chrome
etc
wdh2100 commented 4 years ago

Please see codesandbox ( https://codesandbox.io/s/muidatatables-custom-toolbar-forked-q257d ) and change view column in browser.

  const columns = [
    {
      name: "Name",
      options: {
        display: "false"
      }
    },
    {
      name: "Title",
      options: {
        display: "true"
      }
    },
    {
      name: "Location",
      options: {}
    }
  ];

I think this part needs to be changed to the state.

This issue was made very well. Thank you