Replies: 10 comments 21 replies
-
initialState.columnVisibility in V8 |
Beta Was this translation helpful? Give feedback.
-
On V8, You can use setColumnVisibility to change the visibility state like this.
|
Beta Was this translation helpful? Give feedback.
-
In the const [columnVisibility, setColumnVisibility] = React.useState<VisibilityState>({
'column-name-to-hide-by-default': false,
})
// (...)
const table = useReactTable({
// (...)
state: {
sorting,
columnVisibility, // <-- State.
columnFilters,
},
onColumnVisibilityChange: setColumnVisibility, // <-- To manipulate visibility state.
}) |
Beta Was this translation helpful? Give feedback.
-
Is there another way to pass in multiple data properties for a row that are rendered inside a inside single cell without defining them as columns that are always hidden? Concrete example: I have a site The only way I don't get a {
accessorKey: 'url',
}, It works, it just feels like I am abusing the concept of a 'column' that I never intended on displaying as such. See also #4893 |
Beta Was this translation helpful? Give feedback.
-
It's even simpler by using an effect and just hiding the columns you want to be hidden: React.useEffect(() => {
table.setColumnVisibility({
locationId: false,
leadType: false,
source: false,
});
}, [table]); |
Beta Was this translation helpful? Give feedback.
-
const table = useReactTable({
data,
columns,
state: {
columnVisibility: {
id: false //replace `id` with your column identifier
}
}
}); |
Beta Was this translation helpful? Give feedback.
-
Using Ver 8: Function GetInVisibleColumn() takes an array of finalColumnDef and filters out the columns that have the visible property set to false. It then creates a new object (removedColumn) where the keys are the accessorKey properties of the invisible columns, and the values are set to false. |
Beta Was this translation helpful? Give feedback.
-
Use initialState.columnVisibility in v8 if you want to reset the columns
|
Beta Was this translation helpful? Give feedback.
-
If you want to manage the initial visibility in column definition: Extend the column meta to add hidden key
Add the columns you marked with hidden in the initial column visibility state
I had to use any for the column definition because typescript didnt want me to use accessorKey. I dont know why. |
Beta Was this translation helpful? Give feedback.
-
This works for me ` const [rowSelection, setRowSelection] = React.useState({}); const [columnVisibility, setColumnVisibility] = const [columnFilters, setColumnFilters] = React.useState( const [filtering, setFiltering] = React.useState(""); const table = useReactTable({ |
Beta Was this translation helpful? Give feedback.
-
I read this discussion abut hiding columns in v7
The docs suggest that there is a initialState.hiddenColumns in the use(Framework)Table , but this is throwing, saying that hiddenColumns does not exist
Maybe i am putting it in the wrong spot or not writing it right
Beta Was this translation helpful? Give feedback.
All reactions