Data grid
The table people work in: sort, resize, pin and hide columns, edit cells in place, and save views.
Installation
npm i @uisatin/ui @uisatin/proimport '@uisatin/ui/styles.css'
import '@uisatin/pro/styles.css'
import { DataGrid } from '@uisatin/pro/data-grid'Part of Satin Pro, the licensed edition: @uisatin/pro on top of @uisatin/ui at the same version, its stylesheet after Free's. Satin Pro isn't on npm yet.
About 42.4 kB of JavaScript, minified and gzipped, on top of the @uisatin/uicomponents it uses (React aside).
First time with Satin? Set it up once, styles and fonts included, with the installation guide.
API Reference
The DataGrid component (Satin Pro, @uisatin/pro/data-grid) draws rows through typed columns: { key, header, label, width, minWidth, maxWidth, pinned, sortable, hideable, editable, align, renderCell, renderEditor }, where key names a field of the row and types the value renderCell and renderEditor get (a computed: true column takes any key and draws its own cells). Sort, selection, column visibility, order and sizing are each controlled (sort, selection, columnVisibility, columnOrder, columnSizing) or uncontrolled (default…), with an on…Change. onCellEdit(rowId, key, value) saves an edit: update rows in it, and return a promise to show the cell saving, or reject to show the error. Give the grid a height; above 200 rows only the rows on screen are drawn. The toolbar slot takes DataGridToolbar, DataGridColumnsMenu and DataGridViewMenu (views, value, filters, onValueChange: saved views of the sort, the columns and your filters).
| Prop | Type | Default |
|---|---|---|
columns | DataGridColumn<R>[] | — |
rows | R[] | — |
getRowId | (row: R) => string | row.id |
label | string | — |
rowLabel | (row: R) => string | — |
sort / defaultSort | DataGridSort | null |
onSortChange | (sort: DataGridSort) => void | — |
manualSort | boolean | false |
selectable | boolean | false |
selection / defaultSelection | string[] | [] |
onSelectionChange | (ids: string[]) => void | — |
columnVisibility / defaultColumnVisibility | Record<string, boolean> | {} |
columnOrder / defaultColumnOrder | string[] | [] |
columnSizing / defaultColumnSizing | Record<string, number> | {} |
density | "default""compact" | "default" |
onCellEdit | (rowId: string, key: string, value: unknown) => unknown | — |
loading | boolean | false |
error | ReactNodeboolean | — |
onRetry | () => void | — |
filtered | boolean | false |
onClearFilters | () => void | — |
empty | ReactNode | — |
noResults | ReactNode | — |
virtualize | boolean | above 200 rows |
pageSize | number | — |
page / defaultPage | number | 1 |
onPageChange | (page: number) => void | — |
toolbar | ReactNode | — |
className | string | — |
ref | Ref<HTMLDivElement> | — |
...props | ComponentProps<'div'>Other attributes go to <div> | — |
Accessibility
A grid (APG Grid pattern) named by label, with aria-rowcount and aria-colcount and each row and cell numbered, so the count stays right while only the rows on screen exist. One cell at a time is in the tab order; a sortable header holds a button and sets aria-sort. With selectable the grid is aria-multiselectable and rows set aria-selected; the checkboxes are named "Select <name>" after the first column or rowLabel. Each resize handle is a focusable separator named "Resize <column>" with its width as aria-valuenow. An editor is named after its column. A saving cell is aria-busy; a failed one is aria-invalid and described by its error. Sorting, saves and views are read out from a polite status region. The Columns menu is a menu of menuitemcheckbox rows; the view menu says "View: <name>, unsaved changes" when the grid has moved from the view.
| Key | Action |
|---|---|
| Tab | Moves into the grid, onto the cell last focused. From a header, moves on to its resize handle; Tab again leaves the grid. |
| ←or→or↑or↓ | Moves one cell; ← and → are mirrored right to left. The header row is part of the grid. |
| HomeorEnd | Moves to the first or last cell of the row; with ⌃ or ⌘, of the grid. |
| Page UporPage Down | Moves up or down by a screen of rows. |
| EnterorSpace | On a sortable header: sorts ascending, then descending, then not at all. On a checkbox (Space): selects the row, or every row. |
| ⇧ Space | Selects or clears the focused cell’s row. |
| EnterorF2 | On an editable cell: opens its editor (double click does too). On a cell whose save failed: edits the value that failed. |
| EnterorTab | In an editor: saves. Tab then moves to the next cell, ⇧ Tab to the previous one. |
| Esc | In an editor: cancels. On a cell whose save failed: drops the change. |
| ←or→ | On a resize handle: narrows or widens the column by 8px (40px with ⇧); Home and End go to its narrowest and widest. Enter or Esc goes back to the header. |
| ⌥ ↑or⌥ ↓ | In the Columns menu: moves the highlighted column up or down. |
Something wrong or missing on this page?
Report a problemSuggest an improvement