Caret-Tui

DataTable

An interactive table component with pagination and sorting.

DataTable is a powerful, interactive component for displaying tabular data. It automatically handles pagination, column sorting, and keyboard navigation (left/right arrows for pagination, 's' for sorting).

Usage

import { DataTable } from 'caret-tui';

const data = [
  { id: 1, name: 'Alice', status: 'Active' },
  { id: 2, name: 'Bob', status: 'Offline' }
];

const columns = [
  { header: 'ID', key: 'id', width: 5, sortable: true },
  { header: 'Name', key: 'name', width: 20, sortable: true },
  { header: 'Status', key: 'status', width: 10 }
];

const App = () => (
  <DataTable columns={columns} data={data} pageSize={5} />
);

Props

PropTypeDefaultDescription
idstring'data-table'The focus ID used by FocusProvider.
columnsColumn<T>[]-Configuration for each column.
dataT[]-The array of objects to display.
pageSizenumber10The number of rows to display per page.

Column Definition (Column<T>)

FieldTypeDescription
headerstringThe text to display in the column header.
keykeyof TThe object key to extract the value from.
widthnumberThe character width of the column. Defaults to 15.
align'left' | 'right'The text alignment. Defaults to left.
sortablebooleanEnables sorting by this column when pressing 's'.
render(value: any, item: T) => React.ReactNodeOptional custom render function for complex cell content.

On this page