Data Grid

Grouped Rows

A grid that groups rows: each group gets a header row with its task count and hour total, and collapses with a single button.

  • datagrid
  • grouping
  • collapse
  • table

Preview

1440pxHost theme

Use it with AI

  1. 1. Copy the link.
  2. 2. Write to your agent in your own words and drop the link into the sentence.
  3. 3. The agent opens the link and installs the component from the registry.

put this in the header: https://vibeui.ru/c/datagrid-007?lang=en

Трудозатраты, спринт 14

Hours by task, grouped by discipline
ЗадачаИсполнительЧасы
Макет каталогаОрлова14
Иконки статусовКим6
Ревизия типографикиОрлова4
Сетка заказовГнедин22
Фильтры в шапкеСавва11
Экспорт CSVГнедин8
Отчёт по воронкеЛебедь9
Разметка событийЛебедь5
Всего по спринту79 ч
Show the full instructions

What the link says, spelled out. Use it when your agent cannot open links — paste this text instead.

# Install and place "datagrid-007" (Grouped Rows) from VibeUI

## 1. Install first — do not skip, do not recreate
Run this exact command before writing any code:
npx shadcn@latest add https://vibeui.ru/r/datagrid-007.json

Registry item: https://vibeui.ru/r/datagrid-007.json
Installs to: components/vibeui/datagrid-007.tsx (the exact path follows this project's components.json aliases).
npm dependencies: none.
Registry dependencies: none.

Install it from the registry. Do not recreate it from the description,
do not substitute a similar component from another library, and do not
rewrite it to match the project's existing style.

## 2. What it is
A grid that groups rows: each group gets a header row with its task count and hour total, and collapses with a single button.

A grid with row grouping and collapsible groups: totals are computed per group and the state is announced through aria-expanded. Zero dependencies, one file.

## 3. How to use it
import { Datagrid007 } from "@/components/vibeui/datagrid-007"

<Datagrid007
  caption="Hours by task, grouped by discipline"
  startCollapsed={false}
/>

Read the installed file for the full prop list.

## 4. Where to place it
This is a small inline component. Put it exactly where the user asked,
inside the existing markup. Do not create a new page, section or
wrapper for it. If a similar control already sits in that spot,
replace it instead of adding a second one.

Placement: ___
(The user fills this line in. If it is still blank, ask where to put it
instead of guessing.)

## 5. Keep exactly as installed
- the local --vibeui-datagrid-007-* palette — do not swap it for your theme tokens
- one tbody per group: that expresses grouping in markup rather than with indentation
- aria-expanded on the group button — otherwise the collapsed state is never announced
- the total in the group row: a collapsed group without a sum stops saying anything
- scope="colgroup" on the group heading so the cells belong to the group explicitly
- the grid's own light surface: on the dark catalog card dark text disappears without it

## 6. You may change
- the line under the toolbar through caption
- the initial group state through startCollapsed
- the groups and tasks through rows
- the accent color through accent

## 7. Rules
- Groups follow the order of first appearance in rows — sort the data first, the component will not reorder it.
- There is a single nesting level: a tree needs a different data shape and per-level indentation.
- «Collapse all» and «Expand all» hit every group at once and do not remember the previous state.
- Do not lift the CSS variables into globals.css: the component has to stay a single file.

## 8. Verify
- it renders with no console errors;
- it looks like the preview on the VibeUI page you copied this from;
- if it does not, you changed something listed in section 5 — put it back.

For developers

npx shadcn@latest add https://vibeui.ru/r/datagrid-007.json
https://vibeui.ru/r/datagrid-007.json

Компонент самодостаточен: один файл, без зависимостей, палитра в --vibeui-datagrid-007-*. Клиентский: useState хранит список свёрнутых групп. Каждая группа — отдельный tbody, поэтому группировка выражена разметкой, а не отступами. Строка-заголовок группы использует th scope=colgroup, внутри неё кнопка с aria-expanded; стрелка поворачивается transform, поэтому состояние видно и без чтения текста. Итоги по группе и по спринту считаются из тех же строк — свёрнутая группа без суммы теряет смысл. Прокрутка вынесена в контейнер с role=region, aria-label и tabindex=0.

Component source

The same file your agent installs. Here in case you would rather copy it by hand.

"use client"

import { useState } from "react"
import type { ComponentPropsWithoutRef, CSSProperties } from "react"

export type Datagrid007Row = {
  group: string
  task: string
  owner: string
  hours: number
}

export type Datagrid007Props = Omit<
  ComponentPropsWithoutRef<"section">,
  "children"
> & {
  rows?: Datagrid007Row[]
  caption?: string
  startCollapsed?: boolean
  accent?: string
}

// Идея компонента: строки собраны в группы, у каждой группы своя строка-
// заголовок с итогом и кнопкой сворачивания. Итог считается по группе, а не
// подписывается руками, поэтому свёрнутая группа не теряет смысла. Кнопка
// несёт aria-expanded, а сама строка группы остаётся строкой таблицы —
// разметка не рассыпается на вложенные таблицы.
const STYLES = `
:where([data-vibeui-block="datagrid-007"]){
--vibeui-datagrid-007-bg:oklch(1 0 0);
--vibeui-datagrid-007-fg:oklch(0.23 0.014 300);
--vibeui-datagrid-007-muted:oklch(0.55 0.014 300);
--vibeui-datagrid-007-border:oklch(0.92 0.006 300);
--vibeui-datagrid-007-head:oklch(0.975 0.003 300);
--vibeui-datagrid-007-group:oklch(0.955 0.008 300);
--vibeui-datagrid-007-accent:oklch(0.5 0.16 320);
--vibeui-datagrid-007-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="datagrid-007"]{
box-sizing:border-box;width:100%;max-width:50rem;margin:0 auto;
background:var(--vibeui-datagrid-007-bg);color:var(--vibeui-datagrid-007-fg);
border:1px solid var(--vibeui-datagrid-007-border);border-radius:0.875rem;
font-family:var(--vibeui-datagrid-007-font);overflow:hidden;
}
[data-vibeui-block="datagrid-007"] *{box-sizing:border-box}
[data-vibeui-block="datagrid-007"] [data-part="bar"]{
display:flex;flex-wrap:wrap;align-items:center;gap:0.5rem;
padding:0.75rem 0.875rem;border-bottom:1px solid var(--vibeui-datagrid-007-border);
}
[data-vibeui-block="datagrid-007"] [data-part="title"]{margin:0;font-size:0.875rem;font-weight:650;margin-inline-end:auto}
[data-vibeui-block="datagrid-007"] [data-part="bar"] button{
appearance:none;cursor:pointer;font:inherit;font-size:0.75rem;
padding:0.3125rem 0.625rem;border-radius:0.5rem;
border:1px solid var(--vibeui-datagrid-007-border);
background:var(--vibeui-datagrid-007-bg);color:var(--vibeui-datagrid-007-fg);
}
[data-vibeui-block="datagrid-007"] [data-part="bar"] button:focus-visible{outline:2px solid var(--vibeui-datagrid-007-accent);outline-offset:2px}
[data-vibeui-block="datagrid-007"] [data-part="scroll"]{overflow-x:auto}
[data-vibeui-block="datagrid-007"] [data-part="scroll"]:focus-visible{outline:2px solid var(--vibeui-datagrid-007-accent);outline-offset:-2px}
[data-vibeui-block="datagrid-007"] table{width:100%;border-collapse:collapse;font-size:0.8125rem}
[data-vibeui-block="datagrid-007"] caption{
padding:0 0.875rem 0.625rem;text-align:left;
font-size:0.75rem;color:var(--vibeui-datagrid-007-muted);
}
[data-vibeui-block="datagrid-007"] th,
[data-vibeui-block="datagrid-007"] td{
padding:0.4375rem 0.875rem;text-align:left;white-space:nowrap;
border-top:1px solid var(--vibeui-datagrid-007-border);
}
[data-vibeui-block="datagrid-007"] thead th{background:var(--vibeui-datagrid-007-head);font-weight:600}
[data-vibeui-block="datagrid-007"] [data-align="end"]{text-align:right;font-variant-numeric:tabular-nums}
[data-vibeui-block="datagrid-007"] [data-part="group-cell"]{padding:0;background:var(--vibeui-datagrid-007-group)}
[data-vibeui-block="datagrid-007"] [data-part="group"]{
display:flex;align-items:center;gap:0.5rem;width:100%;
appearance:none;border:0;background:none;cursor:pointer;font:inherit;font-weight:650;
padding:0.5rem 0.875rem;color:inherit;text-align:left;
}
[data-vibeui-block="datagrid-007"] [data-part="group"]:focus-visible{outline:2px solid var(--vibeui-datagrid-007-accent);outline-offset:-2px}
[data-vibeui-block="datagrid-007"] [data-part="caret"]{
color:var(--vibeui-datagrid-007-accent);font-size:0.625rem;
transition:transform .16s ease;transform:rotate(90deg);
}
[data-vibeui-block="datagrid-007"] [data-part="group"][aria-expanded="false"] [data-part="caret"]{transform:rotate(0deg)}
[data-vibeui-block="datagrid-007"] [data-part="count"]{
font-weight:500;font-size:0.75rem;color:var(--vibeui-datagrid-007-muted);
}
[data-vibeui-block="datagrid-007"] [data-part="sum"]{
margin-inline-start:auto;font-variant-numeric:tabular-nums;font-size:0.8125rem;
}
[data-vibeui-block="datagrid-007"] [data-part="task"]{padding-left:2.25rem;font-weight:500}
[data-vibeui-block="datagrid-007"] [data-part="owner"]{color:var(--vibeui-datagrid-007-muted)}
[data-vibeui-block="datagrid-007"] tfoot td{background:var(--vibeui-datagrid-007-head);font-weight:650}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="datagrid-007"] *{animation:none!important;transition:none!important}}
`

const DEFAULT_ROWS: Datagrid007Row[] = [
  { group: "Дизайн", task: "Макет каталога", owner: "Орлова", hours: 14 },
  { group: "Дизайн", task: "Иконки статусов", owner: "Ким", hours: 6 },
  { group: "Дизайн", task: "Ревизия типографики", owner: "Орлова", hours: 4 },
  { group: "Разработка", task: "Сетка заказов", owner: "Гнедин", hours: 22 },
  { group: "Разработка", task: "Фильтры в шапке", owner: "Савва", hours: 11 },
  { group: "Разработка", task: "Экспорт CSV", owner: "Гнедин", hours: 8 },
  { group: "Аналитика", task: "Отчёт по воронке", owner: "Лебедь", hours: 9 },
  { group: "Аналитика", task: "Разметка событий", owner: "Лебедь", hours: 5 },
]

/**
 * Сетка с группировкой строк: у каждой группы строка-заголовок с итогом
 * и сворачиванием. Один файл, ноль зависимостей, собственная палитра.
 */
export function Datagrid007({
  rows = DEFAULT_ROWS,
  caption = "Часы по задачам, сгруппированные по направлению",
  startCollapsed = false,
  accent,
  className,
  style,
  ...props
}: Datagrid007Props) {
  const names = rows
    .map((row) => row.group)
    .filter((group, index, all) => all.indexOf(group) === index)

  const [closed, setClosed] = useState<string[]>(startCollapsed ? names : [])

  const total = rows.reduce((sum, row) => sum + row.hours, 0)

  const toggle = (group: string) =>
    setClosed((current) =>
      current.includes(group)
        ? current.filter((value) => value !== group)
        : [...current, group],
    )

  const palette = {
    ...(accent ? { "--vibeui-datagrid-007-accent": accent } : null),
    ...style,
  } as CSSProperties

  return (
    <>
      <style href="vibeui-datagrid-007" precedence="medium">
        {STYLES}
      </style>
      <section
        {...props}
        data-vibeui-block="datagrid-007"
        className={className}
        style={palette}
      >
        <div data-part="bar">
          <h3 data-part="title">Трудозатраты, спринт 14</h3>
          <button type="button" onClick={() => setClosed(names)}>
            Свернуть все
          </button>
          <button type="button" onClick={() => setClosed([])}>
            Развернуть все
          </button>
        </div>
        <div
          data-part="scroll"
          role="region"
          aria-label="Таблица трудозатрат, прокручивается вбок"
          tabIndex={0}
        >
          <table>
            <caption>{caption}</caption>
            <thead>
              <tr>
                <th scope="col">Задача</th>
                <th scope="col">Исполнитель</th>
                <th scope="col" data-align="end">
                  Часы
                </th>
              </tr>
            </thead>
            {names.map((group) => {
              const items = rows.filter((row) => row.group === group)
              const open = !closed.includes(group)
              const sum = items.reduce((value, row) => value + row.hours, 0)

              return (
                <tbody key={group}>
                  <tr>
                    <th scope="colgroup" colSpan={3} data-part="group-cell">
                      <button
                        type="button"
                        data-part="group"
                        aria-expanded={open}
                        onClick={() => toggle(group)}
                      >
                        <span data-part="caret" aria-hidden="true">
                          ▶
                        </span>
                        {group}
                        <span data-part="count">{items.length} задач</span>
                        <span data-part="sum">{sum} ч</span>
                      </button>
                    </th>
                  </tr>
                  {open
                    ? items.map((row) => (
                        <tr key={row.task}>
                          <th scope="row" data-part="task">
                            {row.task}
                          </th>
                          <td data-part="owner">{row.owner}</td>
                          <td data-align="end">{row.hours}</td>
                        </tr>
                      ))
                    : null}
                </tbody>
              )
            })}
            <tfoot>
              <tr>
                <td colSpan={2}>Всего по спринту</td>
                <td data-align="end">{total} ч</td>
              </tr>
            </tfoot>
          </table>
        </div>
      </section>
    </>
  )
}