DataTable
Sortable, searchable, selectable, paginated table that turns into cards on phones.
Example
| Bedside dial | Bedroom | Online | 86% | |
| Kitchen puck | Kitchen | Online | 54% | |
| Hall panel | Hallway | Online | 100% | |
| Kids lamp | Kids room | Offline | 12% |
import { Badge, DataTable, type ColumnDef } from "@porcelana/ui";
interface Device {
id: string;
name: string;
room: string;
battery: number;
status: "Online" | "Offline";
}
const devices: Device[] = [
{ id: "d1", name: "Bedside dial", room: "Bedroom", battery: 86, status: "Online" },
{ id: "d2", name: "Kitchen puck", room: "Kitchen", battery: 54, status: "Online" },
{ id: "d3", name: "Hall panel", room: "Hallway", battery: 100, status: "Online" },
{ id: "d4", name: "Kids lamp", room: "Kids room", battery: 12, status: "Offline" },
{ id: "d5", name: "Desk pebble", room: "Office", battery: 71, status: "Online" },
{ id: "d6", name: "Garden chime", room: "Terrace", battery: 39, status: "Offline" }
];
const columns: ColumnDef<Device, unknown>[] = [
{ accessorKey: "name", header: "Device" },
{ accessorKey: "room", header: "Room" },
{
accessorKey: "status",
header: "Status",
cell: (c) => (
<Badge tone={c.getValue() === "Online" ? "success" : "danger"} dot>
{c.getValue<string>()}
</Badge>
)
},
{ accessorKey: "battery", header: "Battery", cell: (c) => `${c.getValue<number>()}%` }
];
export default function Example() {
return (
<DataTable
data={devices}
columns={columns}
caption="Alarm devices"
selectable
searchable
searchLabel="Search devices"
pageSize={4}
getRowId={(d) => d.id}
getRowLabel={(d) => d.name}
/>
);
}Import
import { DataTable } from "@porcelana/ui";
import "@porcelana/ui/styles.css"; // once, at your app rootProps
Generated from the TypeScript types. Standard HTML attributes are passed through and not listed.
DataTable
Sortable, filterable, selectable, paginated table on TanStack Table. Under 640px it renders a card list with sort chips; selection becomes tap-to-select.
| Prop | Type | Default | Description |
|---|---|---|---|
captionrequired | string | – | Describes the table for screen readers. Visible unless `hideCaption`. |
columnsrequired | ColumnDef<TData, unknown>[] | – | TanStack Table column definitions. A string header becomes the sort label. |
datarequired | TData[] | – | Rows to display. |
className | string | – | Class on the outer wrapper. |
emptyText | ReactNode | No results | Shown when no rows match. |
getRowId | ((row: TData, index: number) => string) | – | Stable id per row; keys selection state. Defaults to the row index. |
getRowLabel | ((row: TData) => string) | – | Name of a row, used in "Select <name>" labels and mobile card titles. |
hideCaption | boolean | – | Keep the caption for screen readers but hide it visually. |
initialSorting | SortingState | [] | Sorting on first render, e.g. [{ id: "name", desc: false }]. |
layout | "table" | "auto" | "cards" | auto | Force a layout instead of following the 640px breakpoint. |
onRowSelectionChange | ((selection: RowSelectionState) => void) | – | Called with the selection map ({ [rowId]: true }). |
pageSize | number | 10 | Rows per page. |
renderCard | ((row: Row<TData>) => ReactNode) | – | Custom mobile card body. Defaults to "Column: value" lines. |
rowSelection | RowSelectionState | – | Controlled selection map. |
searchable | boolean | – | Shows a search field filtering every column. |
searchLabel | string | Search | Accessible name and placeholder of the search field. |
selectable | boolean | – | Adds a checkbox column (and tap-to-select cards on mobile). |
toolbar | ((table: Table<TData>) => ReactNode) | – | Content for the toolbar, e.g. bulk actions. Receives the table instance. |
Accessibility
- A captioned table; sortable headers are buttons and the header cells carry aria-sort.
- Row checkboxes are named after the row (getRowLabel); select-all is page-scoped and tri-state.
- Result counts are announced live after searching or paging.
- The scroll area is a focusable, labelled region so keyboard users can scroll wide tables.
Mobile
- Under 640px rows become tap-to-select cards, and sort options become a row of chips.
- Force a layout with layout="table" or layout="cards".