T
TanStack3y ago
xenial-black

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
conscious-sapphire3y 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-black
xenial-blackOP3y ago
const [columnVisibility, setColumnVisibility] = React.useState({"Pair": true, "Quantity": true, "Price": false})
No description
xenial-black
xenial-blackOP3y ago
No description
xenial-black
xenial-blackOP3y 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
conscious-sapphire3y 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

Did you find this page helpful?