DataTable

A feature-rich data table pattern with column-based sorting, row selection via checkboxes, loading skeleton placeholders, configurable empty states, and click-through row interactions. Supports striped rows and compact mode.

Import

import { DataTable } from '@wavebooking/aqua-fusion';

Preview

Loading preview...

Usage

const columns = [
  { key: 'name', header: 'Name', cell: (row) => row.name, sortable: true },
  { key: 'email', header: 'Email', cell: (row) => row.email },
  { key: 'role', header: 'Role', cell: (row) => <Badge>{row.role}</Badge>, align: 'center' },
];

<DataTable
  data={users}
  columns={columns}
  keyExtractor={(row) => row.id}
  sortColumn={sortCol}
  sortDirection={sortDir}
  onSortChange={(col, dir) => { setSortCol(col); setSortDir(dir); }}
  onRowClick={(row) => router.push(`/users/${row.id}`)}
  emptyState={{ title: 'No users found', description: 'Try adjusting your search filters.' }}
/>

Props

PropTypeDefaultDescription
data*T[]-Array of data objects to display as rows.
columns*Column<T>[]-Column definitions that control headers and cell rendering.
keyExtractor*(row: T, index: number) => string | number-Function to extract a unique key from each row.
selectablebooleanfalseWhether to show row selection checkboxes.
selectedKeysSet<string | number>-Set of currently selected row keys.
onSelectionChange(selectedKeys: Set<string | number>) => void-Callback when row selection changes.
sortColumnstring-Key of the currently sorted column.
sortDirection'asc' | 'desc' | null-Current sort direction.
onSortChange(column: string, direction: 'asc' | 'desc' | null) => void-Callback when sort column or direction changes.
loadingbooleanfalseWhether the table is in a loading state. Shows skeleton rows.
loadingRowsnumber5Number of skeleton rows to display when loading.
emptyState{ title: string; description?: string; icon?: ReactNode; action?: ReactNode }-Configuration for the empty state displayed when data is empty.
onRowClick(row: T, index: number) => void-Callback when a row is clicked.
hoverablebooleantrueWhether rows have a hover highlight effect.
stripedbooleanfalseWhether to use alternating row background colors.
compactbooleanfalseWhether to use reduced cell padding.
classNamestring-Additional CSS classes for the table container.

Column<T>

PropertyTypeDescription
keystringUnique key for the column.
headerReactNodeColumn header content.
cell(row: T, index: number) => ReactNodeCell renderer function.
sortablebooleanWhether the column supports sorting.
widthstringColumn width as a CSS value.
align'left' | 'center' | 'right'Text alignment for header and cells.
classNamestringAdditional CSS class for the column cells.