# Data Table

A table with sorting, filtering, pagination, row selection and column visibility, built on TanStack Table.

```tsx
"use client"

import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import {
  DataTable,
  DataTableColumnHeader,
  DataTablePagination,
  DataTableViewOptions,
  createDataTableColumnHelper,
  dataTableSelectColumn,
  useDataTable,
} from "@/components/ui/data-table"
import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuGroup,
  DropdownMenuItem,
  DropdownMenuLabel,
  DropdownMenuSeparator,
  DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import { Input } from "@/components/ui/input"
import { HStack, VStack } from "@/components/ui/stack"
import { widths } from "@/theme/widths"
import { DotsThreeIcon } from "@phosphor-icons/react/dist/csr/DotsThree"

type Payment = {
  id: string
  amount: number
  status: "pending" | "processing" | "succeeded" | "failed"
  email: string
}

const payments: Payment[] = [
  { id: "pay_7f3k", amount: 316, status: "succeeded", email: "euler@example.com" },
  { id: "pay_2m8q", amount: 242, status: "succeeded", email: "gauss@example.com" },
  { id: "pay_9x1d", amount: 837, status: "processing", email: "noether@example.com" },
  { id: "pay_4c6v", amount: 874, status: "succeeded", email: "curie@example.com" },
  { id: "pay_8b2n", amount: 721, status: "failed", email: "turing@example.com" },
  { id: "pay_1h5t", amount: 128.5, status: "pending", email: "riemann@example.com" },
  { id: "pay_6r9w", amount: 64, status: "succeeded", email: "hopper@example.com" },
  { id: "pay_3j7p", amount: 1250, status: "processing", email: "ramanujan@example.com" },
  { id: "pay_5s4z", amount: 19.99, status: "failed", email: "fermat@example.com" },
  { id: "pay_0y8e", amount: 432, status: "pending", email: "kepler@example.com" },
  { id: "pay_7u2a", amount: 590, status: "succeeded", email: "newton@example.com" },
  { id: "pay_2g6l", amount: 77.25, status: "succeeded", email: "galois@example.com" },
]

const currency = new Intl.NumberFormat("en-US", { style: "currency", currency: "USD" })

function PaymentActions({ payment }: { payment: Payment }) {
  return (
    <DropdownMenu>
      <DropdownMenuTrigger
        render={<Button variant="ghost" size="icon-xs" aria-label={`Actions for ${payment.id}`} />}
      >
        <DotsThreeIcon aria-hidden="true" />
      </DropdownMenuTrigger>
      <DropdownMenuContent align="end">
        <DropdownMenuGroup>
          <DropdownMenuLabel>Actions</DropdownMenuLabel>
          <DropdownMenuItem onClick={() => navigator.clipboard.writeText(payment.id)}>
            Copy ID
          </DropdownMenuItem>
        </DropdownMenuGroup>
        <DropdownMenuSeparator />
        <DropdownMenuGroup>
          <DropdownMenuItem>Open payer</DropdownMenuItem>
          <DropdownMenuItem>Download receipt</DropdownMenuItem>
        </DropdownMenuGroup>
      </DropdownMenuContent>
    </DropdownMenu>
  )
}

const helper = createDataTableColumnHelper<Payment>()

const columns = helper.columns([
  dataTableSelectColumn<Payment>(),
  helper.accessor("status", {
    header: "Status",
    enableSorting: false,
    meta: { label: "Status" },
    cell: ({ cell }) => <Badge variant="outline">{cell.getValue()}</Badge>,
  }),
  helper.accessor("email", {
    header: ({ column }) => <DataTableColumnHeader column={column} />,
    filterFn: "includesString",
    meta: { label: "Email" },
  }),
  helper.accessor("amount", {
    header: ({ column }) => <DataTableColumnHeader column={column} />,
    meta: { label: "Amount", align: "end" },
    cell: ({ cell }) => currency.format(cell.getValue()),
  }),
  helper.display({
    id: "actions",
    enableHiding: false,
    meta: { align: "end" },
    cell: ({ row }) => <PaymentActions payment={row.original} />,
  }),
])

export default function DataTableDemo() {
  const table = useDataTable({
    data: payments,
    columns,
    getRowId: (payment) => payment.id,
    initialState: { pagination: { pageIndex: 0, pageSize: 5 } },
  })
  const email = table.getColumn("email")

  return (
    <VStack gap={4} width="100%">
      <HStack justify="between" align="center" gap={2}>
        <Input
          placeholder="Filter emails…"
          aria-label="Filter emails"
          xstyle={widths.narrow}
          value={String(email?.getFilterValue() ?? "")}
          onChange={(event) => email?.setFilterValue(event.target.value)}
        />
        <DataTableViewOptions table={table} />
      </HStack>
      <DataTable table={table} />
      <DataTablePagination table={table} pageSizes={[5, 10, 20]} />
    </VStack>
  )
}
```

## Installation

**Command**

```bash
npx shadcn@latest add @arene/data-table
```

Needs the [arene setup](https://www.arene.style/docs/installation) first. Also adds [Button](https://www.arene.style/docs/components/button), [Checkbox](https://www.arene.style/docs/components/checkbox), [Dropdown Menu](https://www.arene.style/docs/components/dropdown-menu), [Select](https://www.arene.style/docs/components/select), [Stack](https://www.arene.style/docs/components/stack), [Table](https://www.arene.style/docs/components/table) and [Text](https://www.arene.style/docs/components/text).

**Manual**

1. Install the packages it imports:

   ```bash
   npm install @tanstack/react-table @stylexjs/stylex @phosphor-icons/react
   ```

2. Set up the token layer and the StyleX compiler, if you have not already. See
   [Installation](https://www.arene.style/docs/installation). Data Table renders through the
   [Table](https://www.arene.style/docs/components/table), and its parts use the
   [Button](https://www.arene.style/docs/components/button), [Checkbox](https://www.arene.style/docs/components/checkbox),
   [Dropdown Menu](https://www.arene.style/docs/components/dropdown-menu),
   [Select](https://www.arene.style/docs/components/select), [Stack](https://www.arene.style/docs/components/stack) and
   [Text](https://www.arene.style/docs/components/text). It also needs `interop.css`, which sizes the
   icons.

3. Paste this source into the file named in its title.

   ```tsx title="components/ui/data-table.tsx"
   "use client"

   import type { ComponentProps, ReactNode } from "react"
   import {
     FlexRender,
     columnFilteringFeature,
     columnVisibilityFeature,
     createColumnHelper,
     createFilteredRowModel,
     createPaginatedRowModel,
     createSortedRowModel,
     filterFn_arrIncludesSome,
     filterFn_equalsString,
     filterFn_includesString,
     globalFilteringFeature,
     rowPaginationFeature,
     rowSelectionFeature,
     rowSortingFeature,
     sortFn_alphanumeric,
     sortFn_basic,
     sortFn_datetime,
     sortFn_text,
     tableFeatures,
     useTable,
     type Column,
     type DisplayColumnDef,
     type ReactTable,
     type RowData,
     type TableOptions,
   } from "@tanstack/react-table"
   import * as stylex from "@stylexjs/stylex"
   import type { StyleXStyles } from "@stylexjs/stylex"
   import { ArrowDownIcon } from "@phosphor-icons/react/dist/csr/ArrowDown"
   import { ArrowUpIcon } from "@phosphor-icons/react/dist/csr/ArrowUp"
   import { CaretDoubleLeftIcon } from "@phosphor-icons/react/dist/csr/CaretDoubleLeft"
   import { CaretDoubleRightIcon } from "@phosphor-icons/react/dist/csr/CaretDoubleRight"
   import { CaretLeftIcon } from "@phosphor-icons/react/dist/csr/CaretLeft"
   import { CaretRightIcon } from "@phosphor-icons/react/dist/csr/CaretRight"
   import { CaretUpDownIcon } from "@phosphor-icons/react/dist/csr/CaretUpDown"
   import { SlidersHorizontalIcon } from "@phosphor-icons/react/dist/csr/SlidersHorizontal"

   import { Button } from "@/components/ui/button"
   import { Checkbox } from "@/components/ui/checkbox"
   import {
     DropdownMenu,
     DropdownMenuCheckboxItem,
     DropdownMenuContent,
     DropdownMenuGroup,
     DropdownMenuLabel,
     DropdownMenuTrigger,
   } from "@/components/ui/dropdown-menu"
   import {
     Select,
     SelectContent,
     SelectGroup,
     SelectItem,
     SelectTrigger,
     SelectValue,
   } from "@/components/ui/select"
   import { HStack } from "@/components/ui/stack"
   import {
     Table,
     TableBody,
     TableCell,
     TableHead,
     TableHeader,
     TableRow,
     type TableAlign,
   } from "@/components/ui/table"
   import { Text } from "@/components/ui/text"
   import { color, space } from "@/theme/tokens.stylex"

   const styles = stylex.create({
     empty: { height: space.s24, color: color.mutedForeground },
     sortStart: {
       marginInlineStart: `calc(-1 * ${space.s2})`,
       marginBlock: `calc(-1 * ${space.s1})`,
     },
     sortEnd: {
       marginInlineEnd: `calc(-1 * ${space.s2})`,
       marginBlock: `calc(-1 * ${space.s1})`,
     },
   })

   const dataTableStyles = {
     empty: styles.empty,
     sort: { start: styles.sortStart, end: styles.sortEnd },
   }

   type DataTableColumnMeta = {
     label?: string
     align?: TableAlign
   }

   const dataTableFeatures = tableFeatures({
     rowSortingFeature,
     sortedRowModel: createSortedRowModel(),
     sortFns: {
       alphanumeric: sortFn_alphanumeric,
       basic: sortFn_basic,
       datetime: sortFn_datetime,
       text: sortFn_text,
     },
     columnFilteringFeature,
     globalFilteringFeature,
     filteredRowModel: createFilteredRowModel(),
     filterFns: {
       arrIncludesSome: filterFn_arrIncludesSome,
       equalsString: filterFn_equalsString,
       includesString: filterFn_includesString,
     },
     rowPaginationFeature,
     paginatedRowModel: createPaginatedRowModel(),
     rowSelectionFeature,
     columnVisibilityFeature,
     columnMeta: {} as DataTableColumnMeta,
   })

   type DataTableFeatures = typeof dataTableFeatures

   type DataTableInstance<TData extends RowData> = ReactTable<DataTableFeatures, TData>

   type DataTableOptions<TData extends RowData> = Omit<
     TableOptions<DataTableFeatures, TData>,
     "features"
   >

   function useDataTable<TData extends RowData>(options: DataTableOptions<TData>) {
     return useTable({ features: dataTableFeatures, ...options })
   }

   function createDataTableColumnHelper<TData extends RowData>() {
     return createColumnHelper<DataTableFeatures, TData>()
   }

   function columnLabel<TData extends RowData, TValue>(
     column: Column<DataTableFeatures, TData, TValue>,
   ) {
     return column.columnDef.meta?.label ?? column.id
   }

   const ariaSorts = { asc: "ascending", desc: "descending" } as const

   function ariaSort<TData extends RowData, TValue>(column: Column<DataTableFeatures, TData, TValue>) {
     if (!column.getCanSort()) return undefined
     const sorted = column.getIsSorted()
     return sorted ? ariaSorts[sorted] : "none"
   }

   type Overrides = { xstyle?: StyleXStyles; className?: string }

   type DataTableProps<TData extends RowData> = Omit<ComponentProps<typeof Table>, "children"> & {
     table: DataTableInstance<TData>
     empty?: ReactNode
   }

   function DataTable<TData extends RowData>({
     table,
     empty = "No results.",
     ...props
   }: DataTableProps<TData>) {
     const rows = table.getRowModel().rows
     return (
       <Table data-slot="data-table" {...props}>
         <TableHeader>
           {table.getHeaderGroups().map((group) => (
             <TableRow key={group.id}>
               {group.headers.map((header) => (
                 <TableHead
                   key={header.id}
                   colSpan={header.colSpan}
                   align={header.column.columnDef.meta?.align}
                   aria-sort={ariaSort(header.column)}
                 >
                   {header.isPlaceholder ? null : <FlexRender header={header} />}
                 </TableHead>
               ))}
             </TableRow>
           ))}
         </TableHeader>
         <TableBody>
           {rows.length > 0 ? (
             rows.map((row) => (
               <TableRow key={row.id} selected={row.getIsSelected()}>
                 {row.getVisibleCells().map((cell) => (
                   <TableCell key={cell.id} align={cell.column.columnDef.meta?.align}>
                     <FlexRender cell={cell} />
                   </TableCell>
                 ))}
               </TableRow>
             ))
           ) : (
             <TableRow>
               <TableCell
                 colSpan={table.getVisibleLeafColumns().length}
                 align="center"
                 xstyle={styles.empty}
               >
                 {empty}
               </TableCell>
             </TableRow>
           )}
         </TableBody>
       </Table>
     )
   }

   type DataTableColumnHeaderProps<TData extends RowData, TValue> = Overrides & {
     column: Column<DataTableFeatures, TData, TValue>
     children?: ReactNode
   }

   function DataTableColumnHeader<TData extends RowData, TValue>({
     column,
     children = columnLabel(column),
     xstyle,
     className,
   }: DataTableColumnHeaderProps<TData, TValue>) {
     if (!column.getCanSort()) return children
     const sorted = column.getIsSorted()
     const Icon = sorted === "asc" ? ArrowUpIcon : sorted === "desc" ? ArrowDownIcon : CaretUpDownIcon
     const align = column.columnDef.meta?.align === "end" ? "end" : "start"
     return (
       <Button
         data-slot="data-table-column-header"
         variant="ghost"
         size="xs"
         iconPosition="end"
         xstyle={[dataTableStyles.sort[align], xstyle]}
         className={className}
         onClick={column.getToggleSortingHandler()}
       >
         {children}
         <Icon aria-hidden="true" />
       </Button>
     )
   }

   function dataTableSelectColumn<TData extends RowData>(): DisplayColumnDef<
     DataTableFeatures,
     TData,
     unknown
   > {
     return {
       id: "select",
       enableSorting: false,
       enableHiding: false,
       header: ({ table }) => (
         <Checkbox
           checked={table.getIsAllPageRowsSelected()}
           indeterminate={table.getIsSomePageRowsSelected() && !table.getIsAllPageRowsSelected()}
           onCheckedChange={(checked) => table.toggleAllPageRowsSelected(checked)}
           aria-label="Select all rows on this page"
         />
       ),
       cell: ({ row }) => (
         <Checkbox
           checked={row.getIsSelected()}
           disabled={!row.getCanSelect()}
           onCheckedChange={(checked) => row.toggleSelected(checked)}
           aria-label="Select row"
         />
       ),
     }
   }

   type DataTableViewOptionsProps<TData extends RowData> = {
     table: DataTableInstance<TData>
     children?: ReactNode
   }

   function DataTableViewOptions<TData extends RowData>({
     table,
     children = "View",
   }: DataTableViewOptionsProps<TData>) {
     return (
       <DropdownMenu>
         <DropdownMenuTrigger
           data-slot="data-table-view-options"
           render={<Button variant="outline" size="sm" iconPosition="start" />}
         >
           <SlidersHorizontalIcon aria-hidden="true" />
           {children}
         </DropdownMenuTrigger>
         <DropdownMenuContent align="end">
           <DropdownMenuGroup>
             <DropdownMenuLabel>Toggle columns</DropdownMenuLabel>
             {table
               .getAllLeafColumns()
               .filter((column) => column.getCanHide())
               .map((column) => (
                 <DropdownMenuCheckboxItem
                   key={column.id}
                   checked={column.getIsVisible()}
                   onCheckedChange={(visible) => column.toggleVisibility(visible)}
                 >
                   {columnLabel(column)}
                 </DropdownMenuCheckboxItem>
               ))}
           </DropdownMenuGroup>
         </DropdownMenuContent>
       </DropdownMenu>
     )
   }

   const rows = (count: number) => `${count} ${count === 1 ? "row" : "rows"}`

   type DataTablePaginationProps<TData extends RowData> = Overrides & {
     table: DataTableInstance<TData>
     pageSizes?: ReadonlyArray<number>
   }

   function DataTablePagination<TData extends RowData>({
     table,
     pageSizes = [10, 20, 30, 40, 50],
     xstyle,
     className,
   }: DataTablePaginationProps<TData>) {
     const { pageIndex, pageSize } = table.state.pagination
     const total = table.getFilteredRowModel().rows.length
     const selected = table.getFilteredSelectedRowModel().rows.length
     const sizes = pageSizes.map((size) => ({ label: String(size), value: size }))
     return (
       <HStack
         data-slot="data-table-pagination"
         justify="between"
         align="center"
         gap={4}
         wrap="wrap"
         xstyle={xstyle}
         className={className}
       >
         <Text size="sm" tone="muted">
           {selected > 0 ? `${selected} of ${rows(total)} selected` : rows(total)}
         </Text>
         <HStack align="center" gap={6} wrap="wrap">
           <HStack align="center" gap={2}>
             <Text size="sm" weight="medium">
               Rows per page
             </Text>
             <Select
               items={sizes}
               value={pageSize}
               onValueChange={(size) => size != null && table.setPageSize(size)}
             >
               <SelectTrigger size="sm" aria-label="Rows per page">
                 <SelectValue />
               </SelectTrigger>
               <SelectContent>
                 <SelectGroup>
                   {sizes.map((size) => (
                     <SelectItem key={size.value} value={size.value}>
                       {size.label}
                     </SelectItem>
                   ))}
                 </SelectGroup>
               </SelectContent>
             </Select>
           </HStack>
           <Text size="sm" weight="medium">
             Page {pageIndex + 1} of {Math.max(1, table.getPageCount())}
           </Text>
           <HStack align="center" gap={2}>
             <Button
               variant="outline"
               size="icon-sm"
               aria-label="First page"
               disabled={!table.getCanPreviousPage()}
               onClick={() => table.firstPage()}
             >
               <CaretDoubleLeftIcon aria-hidden="true" />
             </Button>
             <Button
               variant="outline"
               size="icon-sm"
               aria-label="Previous page"
               disabled={!table.getCanPreviousPage()}
               onClick={() => table.previousPage()}
             >
               <CaretLeftIcon aria-hidden="true" />
             </Button>
             <Button
               variant="outline"
               size="icon-sm"
               aria-label="Next page"
               disabled={!table.getCanNextPage()}
               onClick={() => table.nextPage()}
             >
               <CaretRightIcon aria-hidden="true" />
             </Button>
             <Button
               variant="outline"
               size="icon-sm"
               aria-label="Last page"
               disabled={!table.getCanNextPage()}
               onClick={() => table.lastPage()}
             >
               <CaretDoubleRightIcon aria-hidden="true" />
             </Button>
           </HStack>
         </HStack>
       </HStack>
     )
   }

   export {
     DataTable,
     DataTableColumnHeader,
     DataTablePagination,
     DataTableViewOptions,
     createDataTableColumnHelper,
     dataTableFeatures,
     dataTableSelectColumn,
     dataTableStyles,
     useDataTable,
     type DataTableColumnMeta,
     type DataTableFeatures,
     type DataTableInstance,
     type DataTableOptions,
   }
   ```

4. Change the `@/` imports if your project uses different aliases.

## Usage

```tsx
import { DataTable, createDataTableColumnHelper, useDataTable } from "@/components/ui/data-table"
```

```tsx
type Invoice = { id: string; customer: string; total: number }

const helper = createDataTableColumnHelper<Invoice>()

const columns = helper.columns([
  helper.accessor("id", { header: "Invoice" }),
  helper.accessor("customer", { header: "Customer" }),
  helper.accessor("total", { header: "Total", meta: { align: "end" } }),
])

function Invoices({ data }: { data: Invoice[] }) {
  const table = useDataTable({ data, columns, getRowId: (invoice) => invoice.id })
  return <DataTable table={table} />
}
```

Data Table is a [TanStack Table](https://tanstack.com/table) v9 preset plus the
parts that render it. `useDataTable` is TanStack's `useTable` with sorting,
column and global filtering, pagination, row selection and column visibility
already registered, so the state and methods for all of them are on `table`.
You keep the table instance, and the parts only render it.

> **Note**
>
> Keep `columns` and `data` stable: define them at module scope, in state, or in
> a `useMemo`. A new array on every render makes TanStack rebuild its row models
> each time.

## Basic

`DataTable` renders headers and cells through the [Table](https://www.arene.style/docs/components/table),
and shows a full-width empty row when nothing matches.

```tsx
"use client"

import { DataTable, createDataTableColumnHelper, useDataTable } from "@/components/ui/data-table"

type Invoice = { id: string; customer: string; status: string; total: number }

const invoices: Invoice[] = [
  { id: "INV-1042", customer: "Euler Labs", status: "Paid", total: 1250 },
  { id: "INV-1043", customer: "Kepler Optics", status: "Pending", total: 480 },
  { id: "INV-1044", customer: "Gauss & Co", status: "Overdue", total: 2100 },
  { id: "INV-1045", customer: "Curie Studio", status: "Paid", total: 760 },
  { id: "INV-1046", customer: "Noether Group", status: "Pending", total: 95 },
]

const currency = new Intl.NumberFormat("en-US", { style: "currency", currency: "USD" })

const helper = createDataTableColumnHelper<Invoice>()

const columns = helper.columns([
  helper.accessor("id", { header: "Invoice" }),
  helper.accessor("customer", { header: "Customer" }),
  helper.accessor("status", { header: "Status" }),
  helper.accessor("total", {
    header: "Total",
    meta: { align: "end" },
    cell: ({ cell }) => currency.format(cell.getValue()),
  }),
])

export default function DataTableBasic() {
  const table = useDataTable({ data: invoices, columns, getRowId: (invoice) => invoice.id })
  return <DataTable table={table} />
}
```

## Sorting

Render `DataTableColumnHeader` as a column's header to sort by it. Clicking
cycles ascending, descending and off, and the heading carries `aria-sort`.
`sortFn` picks the comparison; the preset registers `alphanumeric`, `text`,
`datetime` and `basic`.

```tsx
"use client"

import {
  DataTable,
  DataTableColumnHeader,
  createDataTableColumnHelper,
  useDataTable,
} from "@/components/ui/data-table"

type Release = { version: string; date: Date; downloads: number }

const releases: Release[] = [
  { version: "2.4.0", date: new Date(2025, 4, 12), downloads: 18240 },
  { version: "2.3.1", date: new Date(2025, 2, 3), downloads: 30512 },
  { version: "2.3.0", date: new Date(2025, 1, 18), downloads: 9875 },
  { version: "2.2.0", date: new Date(2024, 10, 27), downloads: 44120 },
  { version: "2.1.0", date: new Date(2024, 7, 9), downloads: 12603 },
]

const day = new Intl.DateTimeFormat("en-US", { dateStyle: "medium" })
const count = new Intl.NumberFormat("en-US")

const helper = createDataTableColumnHelper<Release>()

const columns = helper.columns([
  helper.accessor("version", {
    header: ({ column }) => <DataTableColumnHeader column={column}>Version</DataTableColumnHeader>,
    sortFn: "alphanumeric",
  }),
  helper.accessor("date", {
    header: ({ column }) => <DataTableColumnHeader column={column}>Released</DataTableColumnHeader>,
    sortFn: "datetime",
    cell: ({ cell }) => day.format(cell.getValue()),
  }),
  helper.accessor("downloads", {
    header: ({ column }) => (
      <DataTableColumnHeader column={column}>Downloads</DataTableColumnHeader>
    ),
    meta: { align: "end" },
    cell: ({ cell }) => count.format(cell.getValue()),
  }),
])

export default function DataTableSorting() {
  const table = useDataTable({
    data: releases,
    columns,
    getRowId: (release) => release.version,
    initialState: { sorting: [{ id: "date", desc: true }] },
  })
  return <DataTable table={table} />
}
```

## Search

`globalFilterFn` turns on one search across every column. `empty` replaces the
"No results." text.

```tsx
"use client"

import { DataTable, createDataTableColumnHelper, useDataTable } from "@/components/ui/data-table"
import { Input } from "@/components/ui/input"
import { VStack } from "@/components/ui/stack"
import { widths } from "@/theme/widths"

type Member = { name: string; role: string; team: string }

const members: Member[] = [
  { name: "Ada Lovelace", role: "Engineer", team: "Platform" },
  { name: "Grace Hopper", role: "Engineer", team: "Compilers" },
  { name: "Alan Turing", role: "Researcher", team: "Compilers" },
  { name: "Emmy Noether", role: "Manager", team: "Platform" },
  { name: "Marie Curie", role: "Researcher", team: "Imaging" },
]

const helper = createDataTableColumnHelper<Member>()

const columns = helper.columns([
  helper.accessor("name", { header: "Name" }),
  helper.accessor("role", { header: "Role" }),
  helper.accessor("team", { header: "Team" }),
])

export default function DataTableSearch() {
  const table = useDataTable({
    data: members,
    columns,
    getRowId: (member) => member.name,
    globalFilterFn: "includesString",
  })
  return (
    <VStack gap={4} width="100%">
      <Input
        placeholder="Search people…"
        aria-label="Search people"
        xstyle={widths.narrow}
        value={String(table.state.globalFilter ?? "")}
        onChange={(event) => table.setGlobalFilter(event.target.value)}
      />
      <DataTable table={table} empty="No one matches that search." />
    </VStack>
  )
}
```

## Column meta

The preset types `meta` on every column.

| Key     | Type                           | Effect                                             |
| ------- | ------------------------------ | -------------------------------------------------- |
| `label` | `string`                       | The column's name in the view menu and sort header |
| `align` | `"start" \| "center" \| "end"` | Aligns the header and every cell in the column     |

## API reference

### useDataTable

Takes every TanStack `useTable` option except `features`, which is
`dataTableFeatures`. See the
[TanStack Table reference](https://tanstack.com/table/latest/docs/framework/react/react-table).
It subscribes to all table state, so the component that calls it re-renders on
every change, and the parts read the instance it returns.

### createDataTableColumnHelper

`createDataTableColumnHelper<TData>()` is TanStack's column helper bound to the
preset, so `meta`, `sortFn` and `filterFn` are typed against what is registered.

### DataTable

Takes the `table` and every [Table](https://www.arene.style/docs/components/table) prop.

| Prop    | Type                       | Default         |
| ------- | -------------------------- | --------------- |
| `table` | `DataTableInstance<TData>` | —               |
| `empty` | `ReactNode`                | `"No results."` |

A selected row renders with `TableRow`'s `selected` fill.

### DataTableColumnHeader

| Prop       | Type           | Default                |
| ---------- | -------------- | ---------------------- |
| `column`   | `Column`       | —                      |
| `children` | `ReactNode`    | `meta.label` or the id |
| `xstyle`   | `StyleXStyles` | —                      |

A column that can't sort renders its label as plain text.

### DataTablePagination

| Prop        | Type                    | Default                |
| ----------- | ----------------------- | ---------------------- |
| `table`     | `DataTableInstance`     | —                      |
| `pageSizes` | `ReadonlyArray<number>` | `[10, 20, 30, 40, 50]` |
| `xstyle`    | `StyleXStyles`          | —                      |

It shows the row count, or how many rows are selected, then the page size, the
page number and the first, previous, next and last buttons. Set the first page
size with `initialState.pagination` on `useDataTable`.

### DataTableViewOptions

A **View** button that opens a menu with a checkbox for each column that can be
hidden. Columns with `enableHiding: false` are left out.

| Prop       | Type                | Default  |
| ---------- | ------------------- | -------- |
| `table`    | `DataTableInstance` | —        |
| `children` | `ReactNode`         | `"View"` |

### dataTableSelectColumn

`dataTableSelectColumn<TData>()` returns a display column with a checkbox in
each row and a select-all checkbox for the page in the header. It can't be
sorted or hidden.

### dataTableStyles

The style maps the parts use: `empty` for the empty row and `sort` for the
header button's offsets.

### Data attributes

| Attribute                              | On             | Effect                |
| -------------------------------------- | -------------- | --------------------- |
| `data-slot="data-table"`               | the table      | Data table            |
| `data-slot="data-table-column-header"` | a sort button  | Sortable header       |
| `data-slot="data-table-pagination"`    | the pagination | Pagination bar        |
| `data-slot="data-table-view-options"`  | the trigger    | View menu trigger     |
| `data-selected`                        | a row          | Present when selected |
