Material-table: Set default columns for columnsButton

Created on 25 Mar 2019  路  4Comments  路  Source: mbrn/material-table

Is your feature request related to a problem? Please describe.
I have a table with over 40 different columns, this causes the table to be quite lengthy so I use columnsButton: true to allow users to select columns.

Describe the solution you'd like
By default, all columns listed render automatically and are selected within the Show/Hide columns window, It would be nice to have a key/value for the columns prop similar to the below:

columns={ title: 'Name', field: 'name', defaultColumn: true }

Describe alternatives you've considered
Only current alternative that I've seen is to add columns as a state item and update the component on state change. I've not tried this as of yet.

help wanted

All 4 comments

You can add hidden: true to your column definition. It will hide these columns by default.

@mbrn that's exactly what I was looking for, apologies for the confusion on my end, I didn't see the hidden value in docs at first! Thank you for pointing me in the right direction.

No problem @CalebCox , feel free to ask. I can help as possible as

Hi, this doesn't work anymore as hidden=true, remove the column from the columnsButton list. What is the other alternative? Thanks

Was this page helpful?
0 / 5 - 0 ratings