gregnb / mui-datatables

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

Option to set visible columns #1613

Open nsallis opened 3 years ago

nsallis commented 3 years ago

There is no option (as far as I can tell) to set the view columns. I would have expected an option like setViewColumns which is the setter, and inverse of onViewColumnsChange. The usecase here is that you cannot currently store the columns the user has selected externally (localstorage or url), and then apply that later without doing the legwork to parse, and check each column when setting display in the column options. Perhaps I am missing something in the docs?

Expected Behavior

There is a prop (in options) that takes an array of column names that are visible by default which internally sets display for each column, over-riding whatever is set by default in the column config. ex:

<MuiDatatable
columns={[{name: 'age', options: {display: true}}, {name: 'firstName', options: {display: false}}, {name: 'lastName'}]}
options: {
setViewColumns: ['firstName', 'lastName']
}
...
/>

In this case, I would expect to see first name and last name columns and not age. This makes it easy to extract and update user settings externally, and load them again later.

Current Behavior

No such prop/option.

Your Environment

Tech Version
Material-UI 4.11
MUI-datatables 3.4.1
React 16.13.1
browser Chrome 87
wdh2100 commented 3 years ago

@nsallis

Fixed https://github.com/gregnb/mui-datatables/pull/1581

Upgrade 3.7.3 or display options set string ('true', 'false')