DataTable

A data table on one flat surface. Search, sort, page and select; rows glide into their new order, one highlight stretches between rows, a selection bar takes over the toolbar, and rows open to detail. People, status and number columns are built in. Data.

Open playground
Iris Valeiris@smoui.devDesignActive12
Teo Marshteo@smoui.devFrontendActive4
Noor Haddadnoor@smoui.devResearchInvited7
Cal Riverscal@smoui.devMotionActive2
Ada Quillada@smoui.devWritingPaused3
1-5 of 7

About

DataTable is a React component in the Data category of smoui. It is typed, ships no stylesheet, follows your theme through CSS variables, and honors prefers-reduced-motion. Import it with import { DataTable } from "@ashutoshswamy/smoui" and set columns, rows, rowKey among its 9 props.

Install

Terminal
npm i @ashutoshswamy/smoui

Usage

TSX
import { DataTable } from "@ashutoshswamy/smoui";

<DataTable
  selectable
  searchable
  pageSize={5}
  columns={[
    { key: "name", label: "Member", type: "person", subKey: "email", sortable: true, width: "1.6fr" },
    { key: "status", label: "Status", type: "status", tones: { Active: "good", Paused: "warn" } },
    { key: "seats", label: "Seats", type: "number", sortable: true, width: "80px" },
  ]}
  rows={[{ id: "1", name: "Iris Vale", email: "iris@mail.com", status: "Active", seats: 12, detail: "Opens under the row." }]}
  actions={(ids) => <button onClick={() => remove(ids)}>Remove</button>}
/>

Props 9

columns

type: text, number, person (avatar and name, subKey as a second line) or status (a pill, coloured by tones). width is a CSS grid track.

{ key; label; type?; subKey?; tones?; align?; sortable?; width? }[]
rows

Rows. A detail string opens under the row.

Record<string, string | number>[]
rowKey

Row id field.

stringdefault "id"
selectable / searchable

Checkboxes with a selection bar, and a search box over every field.

booleandefault false
pageSize

Rows per page. Omit to show all.

number
density

Row height.

"comfortable""compact"default "comfortable"
maxHeight

Cap the height in px; the header stays and rows scroll.

number
actions

Buttons for the selection bar, given the selected row ids.

(selected: string[]) => ReactNode
emptyText

Shown when nothing matches.

string