Skip to main content
On this page

DataTable

Feature-rich data table with sorting, custom cells, and loading states.

import { DataTable } from "@ninna-ui/data-display";

pnpm add @ninna-ui/data-display@latest
Includes @ninna-ui/core. CSS setup required.View source

Usage

Import and use the DataTable component in your application.

import { DataTable } from "@ninna-ui/data-display";
const columns = [
{ id: "name", header: "Name", accessorKey: "name", sortable: true },
{ id: "email", header: "Email", accessorKey: "email" },
];
export default function Example() {
return <DataTable data={users} columns={columns} rowKey="id" />;
}

Basic

A sortable data table with column headers.

Live preview
NameEmailRoleStatus
Alice Johnsonalice@example.comAdminActive
Bob Smithbob@example.comEditorActive
Carol Whitecarol@example.comViewerInactive
Dave Browndave@example.comEditorActive

Striped

Alternating row colors for readability.

Live preview
NameEmailRole
Alice Johnsonalice@example.comAdmin
Bob Smithbob@example.comEditor
Carol Whitecarol@example.comViewer
Dave Browndave@example.comEditor

Compact

Reduced padding for dense data.

Live preview
NameEmailRole
Alice Johnsonalice@example.comAdmin
Bob Smithbob@example.comEditor
Carol Whitecarol@example.comViewer
Dave Browndave@example.comEditor

Custom Cells

Custom cell renderers for rich content like badges.

Live preview
NameEmailStatus
Alice Johnsonalice@example.comActive
Bob Smithbob@example.comActive
Carol Whitecarol@example.comInactive
Dave Browndave@example.comActive

Advanced

Search, pagination, row actions, and status badges.

Live preview
Showing 3 of 8 users
NameEmailRoleStatus
Alice Johnsonalice@example.comAdminActive
Bob Smithbob@example.comEditorActive
Carol Whitecarol@example.comViewerInactive

API Reference

Complete list of props for the DataTable component.

DataTable

PropTypeDefaultDescription
aria-labelstring—Accessible label for the table element (recommended for screen readers)
data*T[]—Array of row data
columns*DataTableColumn<T>[]—Column definitions
rowKey*keyof T—Unique key field for rows
stripedbooleanfalseAlternating row background colors
compactbooleanfalseReduced cell padding
borderedbooleanfalseShow cell borders
loadingbooleanfalseShow loading overlay
emptyMessageReactNode—Message when data array is empty
captionstring—Accessible table caption
onSort(state: SortState) => void—Callback when sort changes
classNamestring—Additional CSS classes

DataTableColumn

PropTypeDefaultDescription
id*string—Unique column identifier
header*string | ReactNode—Column header content
accessorKeykeyof T—Key to access row data
cell(row: T) => ReactNode—Custom cell renderer
sortablebooleanfalseWhether the column is sortable

Accessibility

  • Renders a native <table> for full semantic support
  • Supports aria-label prop for labeling the table
  • Sortable columns use aria-sort to announce sort state
  • Sort buttons are keyboard accessible
  • Loading and empty states provide accessible feedback
  • Caption is rendered via <caption> for screen reader context when provided