shadcn.io is an independent project built on shadcn/ui
A Columns button sits above an orders table. Its menu is a checkbox for each hideable column. The heads include Order ID, Customer, Product, Quantity, Total and Date.
Let people hide columns on a wide orders table. A shorter Table is enough if everyone needs the same columns. Base UI in React does not remember hidden columns.
Installation
Usage
<div className="w-full max-w-4xl">
<div className="flex items-center justify-end py-4">
<ColumnsMenu table={table} />
</div>
<div className="rounded-md border bg-background">
<Table>
<TableHeader>
{table.getHeaderGroups().map((headerGroup) => (
<TableRow key={headerGroup.id}>
{headerGroup.headers.map((header) => (
<TableHead key={header.id}>
{header.isPlaceholder ? null : (
<table.FlexRender header={header} />
)}
</TableHead>
))}
</TableRow>
))}
</TableHeader>
<TableBody>
{rows.length > 0 ? (
rows.map((row) => (
<TableRow key={row.id}>
{row.getVisibleCells().map((cell) => (
<TableCell key={cell.id}>
<table.FlexRender cell={cell} />
</TableCell>
))}
</TableRow>
))
) : (
{/* The rest of the file is under Installation. */}FAQ
Where is column visibility stored?
In the table, from columnVisibilityFeature; every column starts visible. Pass initialState: { columnVisibility: { date: false } } to start with a column hidden.
How does the Columns menu toggle a column?
It lists table.getAllColumns() filtered by getCanHide(), checked from column.getIsVisible(). Each DropdownMenuCheckboxItem calls column.toggleVisibility from onCheckedChange.
What text does each item show?
The column's id with capitalize: Id, Customer, Product, Quantity, Total and Date. Give a column meta with a label, or map ids to names, to show something else.
What does the trigger look like?
An outline Button reading Columns with a chevron after the text. The menu opens below it, aligned to its end.
API Reference
Table
Sets colSpan={table.getVisibleLeafColumns().length}. The rest is on the Table page.




