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 visibility
ID | ||||||||
|---|---|---|---|---|---|---|---|---|
| Ava | Thompson | Owner | Engineering | active | 22 | $45,000 | ||
| Liam | Nguyen | Admin | Marketing | inactive | 25 | $47,137 | ||
| Noah | Silva | Editor | Design | pending | 28 | $49,274 | ||
| Emma | Carter | Viewer | Sales | active | 31 | $51,411 | ||
| Olivia | Rossi | Owner | Support | inactive | 34 | $53,548 | ||
| William | Walker | Admin | Engineering | pending | 37 | $55,685 | ||
| Sophia | Patel | Editor | Marketing | active | 40 | $57,822 | ||
| James | Muller | Viewer | Design | inactive | 43 | $59,959 | ||
| Isabella | Park | Owner | Sales | pending | 46 | $62,096 | ||
| Lucas | Reyes | Admin | Support | active | 49 | $64,233 | ||
| $4,120,536 |
Rows per page
1–10 of 48
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.
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.
const columns = [
{ accessorKey: "firstName", enableHiding: false },
]
Always-on columns
Columns with enableHiding: false stay rendered regardless of toolbar or menu actions.