本文へ移動
日本語
「グループ集計表」は Pro に含まれます。解除するとプレビューが表示されます。

仕組み

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.

向いている場面

  • Records that belong to a few groups where the subtotal per group matters: time by project, spend by category, stock by warehouse.

向かない場面

  • Deep hierarchies: use the tree table.
  • Hundreds of rows per group: page or virtualise.

使い方

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}` },
      ]}
    />
  )
}

プロパティ

プロパティ型既定値説明
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.

アクセシビリティ

  • 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.

モーション

Rows: 300ms fade down with a 28ms stagger when a group opens. Chevron: 260ms turn on the reveal curve.

プロジェクトに追加

Pro メンバーはプロンプトをコピーし、コーディングエージェントが無料コンポーネントと同じ手順でソースを導入します。

RowGroupTable.jsxrow-group-table.csstokens.cssREADME.md

2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。

テーブル
「比較テーブル」は Pro に含まれます。解除するとプレビューが表示されます。
「データバー付きテーブル」は Pro に含まれます。解除するとプレビューが表示されます。