ColumnPicker
A menu that shows and hides the columns of a table. One column always stays.
import { ColumnPicker } from '@sypnia/ui/react'
Choosing the columns
Open «Columns». «Joined» starts hidden.
| Name | Role | |
|---|---|---|
| Laura Méndez | laura@northwind.io | Owner |
| Diego Ruiz | diego@northwind.io | Editor |
Code
import { useState } from 'react';
import { ColumnPicker, Table, type Column } from '@sypnia/ui/react';
interface Member { name: string; email: string; role: string; joined: string }
const team: Member[] = [
{ name: 'Laura Méndez', email: 'laura@northwind.io', role: 'Owner', joined: '2024-03-02' },
{ name: 'Diego Ruiz', email: 'diego@northwind.io', role: 'Editor', joined: '2025-07-19' },
];
const all: Column<Member>[] = [
{ id: 'name', header: 'Name', cell: (m) => m.name },
{ id: 'email', header: 'Email', cell: (m) => m.email },
{ id: 'role', header: 'Role', cell: (m) => m.role },
{ id: 'joined', header: 'Joined', cell: (m) => m.joined },
];
// Open «Columns» and tick or untick them. One always stays: a table with no columns says nothing.
export default function Basic() {
const [hidden, setHidden] = useState<string[]>(['joined']);
return (
<div className="sy-stack">
<div className="sy-row sy-row--end"><ColumnPicker columns={all} hidden={hidden} onChange={setHidden} /></div>
<Table label="Members" columns={all.filter((c) => !hidden.includes(c.id))} rows={team} rowKey={(m) => m.email} />
</div>
);
} When to use it
Use it when
- A table has more columns than most people need at once.
- Keep the hidden columns where the person can come back to them (the URL, their settings).
- In a DataTable, pass
columnPickerand it draws this button by itself.
Do not use it when
- The table has three or four columns: show them all.
- You would hide a column to make a table fit a phone: on phones the table is cards already.
For everyone
- It is a menu of checkboxes: arrow keys move, Space or Enter ticks, Escape closes and focus goes back to the button.
- Each item says whether its column is shown.
Props
| ColumnPicker | Type | Default |
|---|---|---|
columnsrequired | { id: string; header: string; }[] | |
hiddenrequiredIds of the columns that are hidden. | string[] | |
onChangerequired | (hidden: string[]) => void |