import { DataTable, DataTableColumnHeader } from '@hanzo/ui'
A column list bound to an array; each cell falls back to the row's raw value when a column names no `cell`.
export function Basic() {return <DataTable columns={columns} data={payments} pageSize={0} />}
`DataTableColumnHeader` turns a header into a toggle, and `filterColumnId` wires a text box to one column.
export function SortableAndFilterable() {const sortable: Array<DataTableColumnDef<Payment>> = [{id: "email",accessorKey: "email",header: ({ column }) => <DataTableColumnHeader column={column} title="Email" />,},{id: "status",accessorKey: "status",header: "Status",cell: ({ row }) => (<Badge variant={row.original.status === "failed" ? "destructive" : "secondary"}>{row.original.status}</Badge>),},columns[2],]return (<DataTable columns={sortable} data={payments} filterColumnId="email" filterPlaceholder="Filter emails…" pageSize={0} />)}
A `select` column with no `header`/`cell` gets a checkbox for free, and `pageSize` turns on the Previous/Next footer.
export function SelectableAndPaginated() {const withSelection: Array<DataTableColumnDef<Payment>> = [{ id: "select", enableSorting: false, enableHiding: false },...columns,]return <DataTable columns={withSelection} data={payments} pageSize={2} />}
export type DataTableSortDirection = 'asc' | 'desc' | false
export interface DataTableColumnApi {id: stringgetIsSorted: () => DataTableSortDirectiontoggleSorting: (desc?: boolean) => voidgetCanHide: () => booleangetIsVisible: () => booleantoggleVisibility: (visible?: boolean) => void}
export interface DataTableRow<TData> {id: stringoriginal: TDatagetValue: (columnId: string) => unknowngetIsSelected: () => booleantoggleSelected: (selected?: boolean) => void}
export interface DataTableInstance<TData> {getAllColumns: () => DataTableColumnApi[]getColumn: (id: string) => DataTableColumnApi | undefinedgetIsAllPageRowsSelected: () => booleangetIsSomePageRowsSelected: () => booleantoggleAllPageRowsSelected: (selected?: boolean) => voidgetFilteredRowModel: () => { rows: Array<DataTableRow<TData>> }getFilteredSelectedRowModel: () => { rows: Array<DataTableRow<TData>> }previousPage: () => voidnextPage: () => voidgetCanPreviousPage: () => booleangetCanNextPage: () => boolean}
export interface DataTableColumnDef<TData> {/** Stable id. Defaults to `String(accessorKey)` when omitted. */id?: stringaccessorKey?: keyof TDataheader?:| React.ReactNode| ((ctx: { column: DataTableColumnApi; table: DataTableInstance<TData> }) => React.ReactNode)cell?: (ctx: { row: DataTableRow<TData>; table: DataTableInstance<TData> }) => React.ReactNodeenableSorting?: booleanenableHiding?: booleanalign?: 'left' | 'center' | 'right'}
export interface DataTableProps<TData> {columns: Array<DataTableColumnDef<TData>>data: TData[]/** Column id filtered by the toolbar's text input. Omit to hide it. */filterColumnId?: stringfilterPlaceholder?: string/** Rows per page. `0` disables pagination (and its footer). Default 10. */pageSize?: numberemptyMessage?: string}
export interface DataTableColumnHeaderProps {column: DataTableColumnApititle: string}