Cómo funciona
Every group is its own tbody, so the structure is real table semantics, not a styled list. The group header row sits on a soft rounded band with a 4px surface gap above it: the first cell is one toggle button with a chevron, the group name and a row count badge, and the other cells show subtotals in semibold under their columns. Member rows are indented under the name and fade down in turn when a group opens. A footer row above a stronger line carries the grand total, and one button folds or unfolds every group. The card is an inline-size container, so columns marked hideBelow step out under 460px.
Úsalo para
- Records that belong to a few groups where the subtotal per group matters: time by project, spend by category, stock by warehouse.
Busca otra opción cuando
- Deep hierarchies: use the tree table.
- Hundreds of rows per group: page or virtualise.
Uso
import { RowGroupTable } from './RowGroupTable.jsx'
export function TimeByProject({ entries }) {
return (
<RowGroupTable
title="Time this week"
caption="Billable time this week"
rows={entries}
groupBy="project"
columns={[
{ key: 'task', title: 'Task' },
{ key: 'person', title: 'Person', hideBelow: true },
{ key: 'hours', title: 'Hours', align: 'right', aggregate: 'sum' },
{ key: 'amount', title: 'Amount', align: 'right', aggregate: 'sum', formatTotal: (v) => `$${v}` },
]}
/>
)
}Propiedades
| Propiedad | Tipo | Por defecto | Qué hace |
|---|---|---|---|
columns | { key, title, align?, width?, render?, aggregate?: 'sum' | 'avg' | 'count' | 'min' | 'max' | (rows) => any, formatTotal?: (v) => ReactNode, hideBelow?: boolean }[] | — | The first column is the row header and holds the group toggle; aggregate fills group subtotals and the grand total. |
rows / rowKey | object[] / (row, i) => key | — | The data, in the order rows should appear inside a group. |
groupBy / groupLabel / groupOrder | string | (row) => key / (key, rows) => ReactNode / key[] | compare | — | Which field groups the rows, how a group is named, and the group order (first appearance by default). |
defaultCollapsed | key[] | [] | Groups folded at first. |
totals | boolean | true | A footer row with the grand total. |
title / subtitle / caption / labels | ReactNode / { total, expandAll, collapseAll, rows(n) } | — | Heading, accessible caption and every built-in string. |
Accesibilidad
- Each group is a tbody whose header cell has scope rowgroup; member rows have row headers.
- The group toggle is a real button with aria-expanded, pointing at its rows with aria-controls while open; Tab reaches every toggle.
- The row count is text in the toggle, so the collapsed size is announced.
- Reduced motion removes the row entrance and the chevron turn.
Movimiento
Rows: 300ms fade down with a 28ms stagger when a group opens. Chevron: 260ms turn on the reveal curve.
Añádelo a tu proyecto
Los miembros Pro copian un prompt y su agente de programación instala el código, igual que con los gratuitos.
RowGroupTable.jsxrow-group-table.csstokens.cssREADME.md
Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.





