How do I hide a column by default setting in v8?
I would like to provide a list with columns that are hidden by default, unless enabled, in v8.
There is a const [columnVisibility, setColumnVisibility] = React.useState({})
but I do not know if I can add stuff in here to make it hide certain columns or perhaps in the columnHelper.accessor
5 Replies
conscious-sapphire•3y ago
To my understanding you would have to populate the
columnVisibility
object yourself before adding it to the table.
It's basically an array of string-boolean tuples which define default visibility.
But I face a similar situation and I agree, this would be nice to set in the columnHelper.accessor
xenial-blackOP•3y ago
const [columnVisibility, setColumnVisibility] = React.useState({"Pair": true, "Quantity": true, "Price": false})

xenial-blackOP•3y ago

xenial-blackOP•3y ago
Thx for the reply, im getting an error though when I try to set the visibility
I got the answer, thanks for guiding me:
const [columnVisibility, setColumnVisibility] = React.useState <VisibilityState>({Pair: true, Quantity: true, Price: false})
remove the quotes around the id! and you have to add <VisibilityState> as the type for some random reason
conscious-sapphire•3y ago
The
<VisibilityState>
is necessary, yes. If you look closer it's basically a Record<string,boolean>
but apparently the TS type inference is not enough for the table