Column visibility
A "Columns" toggle in the toolbar lets users show or hide columns. Each column-actions menu also has a Hide item for the same effect.
Column visibilityToggle columns from the toolbar or the column-actions menu.
tsx
const table = useDataTable({
data,
columns,
getRowId: (row) => row.id,
})
return <DataTable table={table} />
Initial hidden columns
Hide columns from the start with initialState.columnVisibility, mapping a column id to false.
tsx
const table = useDataTable({
data,
columns,
initialState: {
columnVisibility: { startDate: false },
},
})
Prevent hiding a column
Use TanStack's enableHiding: false on a column definition to keep it always visible. It will not appear in the toggle or expose a Hide item.
tsx
const columns = [
{ accessorKey: "firstName", enableHiding: false },
]
Always-on columns
Columns with enableHiding: false stay rendered regardless of toolbar or menu actions.
Leaving a column out of the menu
Set meta.visibleInShowHideMenu: false to keep a column out of the show / hide columns menu while still letting it be hidden from code (column.toggleVisibility).
Related
DensityDensity controls the vertical padding of table rows and the padding around the toolbars.useDataTable optionsuseDataTable(options) accepts everything TanStack's TableOptions accepts (controlled state, on*Change, manual* flags, getRowId, getSubRows, initialState, …; column pinning in state/initialState keeps the left/right shape) plus the data-table options below.Column optionsPer-column configuration lives on the standard TanStack columnDef.meta object, which the table augments with the fields below (fully typed wherever meta is read).