Grouped table
A Table whose rows open onto sub-rows and gather into groups with subtotals, with a pinned first column, a totals row and a compact density.
Installation
npm i @uisatin/ui @uisatin/proimport '@uisatin/ui/styles.css'
import '@uisatin/pro/styles.css'
import { TableGrouped, type TableGroupedColumn } from '@uisatin/pro/table-pro'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 4.1 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 TableGrouped component (Satin Pro, @uisatin/pro/table-pro) is Table, with every Table prop, plus: getSubRows opens rows onto rows of their own; groupBy gathers rows under a header row per value, with the count and each column's subtotal (renderGroup draws the name, groupOrder sets the order); a column's format writes its numbers and aggregate ("sum", "avg", "min", "max", "count" or (rows) => number) totals them in group headers and the footer row, a tfoot; pinned="start" keeps the first column in place with a shadow over what scrolls under it. Totals count the rows you pass, not their sub-rows. With sub-rows or groups the table is a treegrid. The part TableRowToggle is the chevron, for a Table of your own; aggregateRows(rows, column) gives a total as a number.
| Prop | Type | Default |
|---|---|---|
columns | TableGroupedColumn[] | — |
rows | Row[] | — |
getSubRows | (row: Row) => Row[] | undefined | — |
expanded | string[] | — |
defaultExpanded | string[] | [] |
onExpandedChange | (ids: string[]) => void | — |
groupBy | keyof Row | — |
groupOrder | string[] | — |
renderGroup | ({ value, rows }) => ReactNode | — |
collapsedGroups | string[] | — |
defaultCollapsedGroups | string[] | [] |
onCollapsedGroupsChange | (values: string[]) => void | — |
pinned | "start" | — |
footer | boolean | false |
density | "default""compact" | "default" |
selected | string[] | — |
defaultSelected | string[] | [] |
column.format | (value: number) => ReactNode | — |
column.aggregate | "sum""avg""min""max""count"(rows) => number | — |
Accessibility
Table as it is (named by label, aria-sort on sortable headers, named checkboxes), plus: with sub-rows or groups the table takes role="treegrid", and its body rows carry aria-level, aria-posinset, aria-setsize, aria-expanded when they open and aria-selected when selectable. One row is in the Tab order at a time; the row checkboxes stay in it too, as in Table. Each chevron is a button named "Rows under <name>" with aria-expanded, left out of the Tab order because the row's keys do the same. A group header's name is its row header and its count reads "3 rows"; the totals row sits in a tfoot with a "Total" row header. The pinned column's shadow is decoration.
| Key | Action |
|---|---|
| ↓or↑ | Moves to the next or previous row, group headers included. |
| HomeorEnd | Moves to the first or last row. |
| → | Opens a closed row or group; on an open one, moves to its first row. Mirrored right to left. |
| ← | Closes an open row or group; otherwise moves to the row or group it sits under. Mirrored right to left. |
| Enter | Opens or closes the row or group. |
| Space | With selectable, picks or drops the row, or every row of a group. |
| EnterorSpace | On a sortable header: sorts ascending, then descending, then not at all, inside each group. |
Something wrong or missing on this page?
Report a problemSuggest an improvement