Styled table parts for full control, and DataTable for sorting, row selection, loading and empty states.
import { Table, TableHeader, TableBody, TableRow, TableHead, TableCell, DataTable } from "@kivu-ui/react"On this page
import { Table, TableHeader, TableBody, TableRow, TableHead, TableCell, DataTable } from "@kivu-ui/react";| Invoice | Customer | Status | Amount |
|---|---|---|---|
| #1042 | Nyota Coffee | Paid | $1,240.00 |
| #1041 | Ikaze Studio | Overdue | $860.50 |
| #1040 | Kivu Logistics | Paid | $12,400.00 |
import { Badge, Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@kivu-ui/react";
const invoices = [
{ id: "#1042", customer: "Nyota Coffee", status: "Paid", amount: "$1,240.00" },
{ id: "#1041", customer: "Ikaze Studio", status: "Overdue", amount: "$860.50" },
{ id: "#1040", customer: "Kivu Logistics", status: "Paid", amount: "$12,400.00" },
];
export default function Demo() {
return (
<Table className="w-full" density="compact">
<TableHeader>
<TableRow>
<TableHead>Invoice</TableHead>
<TableHead>Customer</TableHead>
<TableHead>Status</TableHead>
<TableHead align="end">Amount</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{invoices.map((inv) => (
<TableRow key={inv.id}>
<TableCell>{inv.id}</TableCell>
<TableCell>{inv.customer}</TableCell>
<TableCell>
<Badge size="sm" tone={inv.status === "Paid" ? "success" : "danger"}>{inv.status}</Badge>
</TableCell>
<TableCell numeric>{inv.amount}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
);
}Describe the columns; sorting and selection are handled for you. Click a header to sort.
| Status | ||||
|---|---|---|---|---|
| Jean Bosco | Engineer | Active | 168.0 | |
| Amara Uwase | Designer | Active | 142.5 | |
| Eric Mugisha | Engineer | Active | 121.3 | |
| Grace Ineza | Product | Invited | 0.0 |
selected: []
import { useState } from "react";
import { Avatar, Badge, DataTable, type DataTableColumn } from "@kivu-ui/react";
interface Member { id: string; name: string; role: string; status: "Active" | "Invited"; hours: number }
const members: Member[] = [
{ id: "1", name: "Amara Uwase", role: "Designer", status: "Active", hours: 142.5 },
{ id: "2", name: "Jean Bosco", role: "Engineer", status: "Active", hours: 168 },
{ id: "3", name: "Grace Ineza", role: "Product", status: "Invited", hours: 0 },
{ id: "4", name: "Eric Mugisha", role: "Engineer", status: "Active", hours: 121.25 },
];
const columns: DataTableColumn<Member>[] = [
{
id: "name", header: "Name", accessor: "name", sortable: true,
cell: (m) => <span className="flex items-center gap-2"><Avatar name={m.name} size="sm" />{m.name}</span>,
},
{ id: "role", header: "Role", accessor: "role", sortable: true },
{ id: "status", header: "Status", accessor: "status", cell: (m) => <Badge size="sm" tone={m.status === "Active" ? "success" : "neutral"}>{m.status}</Badge> },
{ id: "hours", header: "Hours", accessor: "hours", numeric: true, sortable: true, cell: (m) => m.hours.toFixed(1) },
];
export default function Demo() {
const [selected, setSelected] = useState<string[]>([]);
return (
<div className="w-full">
<DataTable
aria-label="Team members"
columns={columns}
data={members}
selectable
selectedIds={selected}
onSelectedIdsChange={setSelected}
defaultSort={{ id: "hours", direction: "desc" }}
/>
<p className="mt-3 font-mono text-xs text-fg-muted">selected: [{selected.join(", ")}]</p>
</div>
);
}| Customer | Total |
|---|
import { DataTable, SegmentedControl, type DataTableColumn } from "@kivu-ui/react";
import { useState } from "react";
const columns: DataTableColumn<{ id: string; name: string; total: number }>[] = [
{ id: "name", header: "Customer", accessor: "name" },
{ id: "total", header: "Total", accessor: "total", numeric: true },
];
export default function Demo() {
const [state, setState] = useState("loading");
return (
<div className="grid w-full gap-4">
<SegmentedControl aria-label="Table state" size="sm" options={["loading", "empty"]} value={state} onValueChange={setState} />
<DataTable
aria-label="Customers"
columns={columns}
data={[]}
loading={state === "loading"}
loadingRows={3}
empty="No customers match these filters"
/>
</div>
);
}Extends <table> attributes.
| Prop | Type | Default | Description |
|---|---|---|---|
density | "compact" | "default" | "comfortable" | "default" | Row height. |
stickyHeader | boolean | false | Keep the header visible while scrolling. Set maxHeight too. |
maxHeight | CSS length | - | Scroll vertically past this height. |
striped | boolean | false | Alternate row backgrounds. |
hover | boolean | true | Highlight the row under the pointer. |
bare | boolean | false | No outer border or radius, e.g. inside a Card. |
wrapperClassName | string | - | Class for the scrolling wrapper. |
| Prop | Type | Default | Description |
|---|---|---|---|
align | "start" | "center" | "end" | "start" | Text alignment. |
sort | "asc" | "desc" | false | - | Current sort. false means sortable but not sorted. |
onSort | () => void | - | Makes the header a sort button. |
| Prop | Type | Default | Description |
|---|---|---|---|
numeric | boolean | false | Right-aligned, same-width digits. |
align | "start" | "center" | "end" | - | Text alignment. |
Also takes the Table props.
| Prop | Type | Default | Description |
|---|---|---|---|
columns | DataTableColumn<T>[] | - | Required. id, header, accessor, cell, sortable, numeric, width… |
data | T[] | - | Required. The rows. |
getRowId | (row, index) => string | row.id | Stable id for selection. |
selectable | boolean | false | Add a checkbox column with select-all. |
selectedIds / onSelectedIdsChange | string[] / (ids) => void | - | Control the selection. |
sort / defaultSort / onSortChange | { id, direction } | null | - | Control the sort. |
manualSort | boolean | false | Don't sort in the browser; sort on the server from onSortChange. |
loading | boolean | false | Show skeleton rows (or dim existing rows). |
empty | ReactNode | - | Shown with no rows. A string becomes an EmptyState title. |
onRowClick | (row: T) => void | - | Make rows clickable. |
Every component also accepts className and forwards its ref. Root CSS class: .kivu-table