Ir al contenido
Español
Tabla agrupada viene con Pro. La vista previa aparece al desbloquearlo.

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

PropiedadTipoPor defectoQué 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 / rowKeyobject[] / (row, i) => key—The data, in the order rows should appear inside a group.
groupBy / groupLabel / groupOrderstring | (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).
defaultCollapsedkey[][]Groups folded at first.
totalsbooleantrueA footer row with the grand total.
title / subtitle / caption / labelsReactNode / { 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.

Tablas
Tabla comparativa viene con Pro. La vista previa aparece al desbloquearlo.
Tabla con barras de datos viene con Pro. La vista previa aparece al desbloquearlo.