- Label
- Icon label
- Field
- Form
- Frontmatter form
- Questionnaire
- Input
- Input group
- Input OTP
- Password input
- Password strength
- Code input
- Number field
- Tag input
- Textarea
- Checkbox
- Radio group
- Language toggle group
- Emoji appearance toggle group
- Emoji picker
- Avatar picker
- AI provider picker
- Select
- Native select
- Combobox
- Language combobox
- Slider
- Calendar
- Switch
- Alert
- Avatar
- Badge
- Card
- AI provider card
- Model info card
- Model list
- Empty
- Item
- Tree item
- File tree
- Icon media
- File type icon
- Font preview
- Image preview
- Kbd
- Table
- Data table
- Data table column header
- Chart
- Code Block
- Code card
- Markdown view
- Attachment
- Bubble
- Marker
- Message
- Chat message
- Chat suggestion item
- Message scroller
- Trace
- Progress
- Spinner
- Sonner
- Toast
- Unsaved changes toolbar
- Unsaved indicator
- Status indicator
- Permission card
- Separator
- Skeleton
- Animated grid pattern
- Meteors
A @tanstack/react-table column's sort-and-hide menu, taking the column directly rather than a shared table instance.
Installation#
pnpm dlx shadcn@latest add @zui/data-table-column-headerThe CLI writes components/data-display/data-table-column-header.tsx, installs
Button, Dropdown menu,
Icon, Text children and Utils, and adds @tanstack/react-table and
lucide-react-native.
Usage#
import {
DataTableColumnHeader,
DataTableColumnHeaderContent,
DataTableColumnHeaderHide,
DataTableColumnHeaderSortAscending,
DataTableColumnHeaderSortDescending,
DataTableColumnHeaderTrigger,
} from '@/components/data-display/data-table-column-header';
import { DropdownMenuSeparator } from '@/components/ui/dropdown-menu';const columns: ColumnDef<FileRow>[] = [
{
accessorKey: 'name',
header: ({ column }) => (
<DataTableColumnHeader column={column}>
<DataTableColumnHeaderTrigger>Name</DataTableColumnHeaderTrigger>
<DataTableColumnHeaderContent>
<DataTableColumnHeaderSortAscending />
<DataTableColumnHeaderSortDescending />
<DropdownMenuSeparator />
<DataTableColumnHeaderHide />
</DataTableColumnHeaderContent>
</DataTableColumnHeader>
),
},
];Render it from a column's header. It takes the column directly, since column definitions live outside the
render tree. A column that neither sorts nor hides takes its title as plain children, with no menu:
<DataTableColumnHeader column={column}>Size</DataTableColumnHeader>The menu draws in the app's PortalHost, as Dropdown menu does.
Composition#
DataTableColumnHeader
|-- DataTableColumnHeaderTrigger
`-- DataTableColumnHeaderContent
|-- DataTableColumnHeaderSortAscending
|-- DataTableColumnHeaderSortDescending
`-- DataTableColumnHeaderHideAPI reference#
DataTableColumnHeader#
Takes every prop of a View, plus:
| Prop | Type | Default |
|---|---|---|
column | Column<TData, TValue> | required |
Holds the column menu's state, and hands column to its parts.
DataTableColumnHeaderTrigger#
Takes every prop of DropdownMenuTrigger except asChild. A ghost button named by its children, the column's
title, followed by an icon for the column's sort direction: up while ascending, down while descending, both ways
while unsorted. A press opens the menu.
DataTableColumnHeaderContent#
Takes every prop of DropdownMenuContent; align defaults to start. Its children are the actions.
DataTableColumnHeaderSortAscending, DataTableColumnHeaderSortDescending, DataTableColumnHeaderHide#
Each takes every prop of DropdownMenuItem. They sort the column ascending, sort it descending, and hide it, with
the default copy "Asc", "Desc" and "Hide", which children replace. Your own onPress runs first, and one that calls
event.preventDefault() skips the action. Each throws outside a DataTableColumnHeader.
Differences from the web#
onPressstands in for the web'sonClick.- The icons are static; the web's play while the trigger or an item is hovered or focused.
- The web's
data-slotattributes are not set; a View takes no data attributes.