Data Grid

Infinite Scroll

A long grid that loads on scroll: a counter and a bar show how many rows have arrived, and a «Load more» button repeats the auto-load for the keyboard.

  • datagrid
  • infinite-scroll
  • progress
  • 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-025?lang=en

Лента событий кассы

Загружено 12 из 48

A batch loads at the bottom edge of the scroll viewport
ВремяСобытиеИсточникСумма, ₽
12:59Заказ оплаченкасса-1120
12:58Возврат оформленкасса-2157
12:57Скидка примененатерминал194
12:56Чек аннулировансамовывоз231
12:55Заказ собранмаркетплейс268
12:54Доставка назначенакасса-1305
12:53Заказ оплаченкасса-2342
12:52Возврат оформлентерминал379
12:51Скидка примененасамовывоз416
12:50Чек аннулированмаркетплейс453
12:49Заказ собранкасса-1490
12:48Доставка назначенакасса-2527
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-025" (Infinite Scroll) 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-025.json

Registry item: https://vibeui.ru/r/datagrid-025.json
Installs to: components/vibeui/datagrid-025.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 long grid that loads on scroll: a counter and a bar show how many rows have arrived, and a «Load more» button repeats the auto-load for the keyboard.

A grid with infinite scrolling, a loaded-rows counter and a progress bar. Zero dependencies, one file.

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

<Datagrid025 caption="Event feed" batchSize={20} />

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-025-* palette — do not swap it for your theme tokens
- the «Load more» button beside the auto-load: scrolling alone cuts off the keyboard
- the 24 px margin before the bottom — without it the threshold is missed on a fast scroll
- the counter and the bar with aria-valuenow: an endless list with no visible bottom disorients
- the sticky header with its own background, or the columns are a mystery deep in the list
- aria-live on the loaded counter so a fetch is heard and not only seen

## 6. You may change
- the line under the toolbar through caption
- the batch size through batchSize
- the event feed through rows
- the accent color through accent

## 7. Rules
- All data sits in memory: swap the slice for a request for the next page to load for real.
- The threshold is in pixels, not per cent: with a viewport taller than a batch the list loads twice at once.
- There is no «loading» state — add a flag for a real request, or the fetch fires twice.
- 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-025.json
https://vibeui.ru/r/datagrid-025.json

Компонент самодостаточен: один файл, без зависимостей, палитра в --vibeui-datagrid-025-*. Клиентский: useState хранит число показанных строк, срез массива даёт видимые. Автозагрузка висит на onScroll контейнера и срабатывает за 24 px до дна — без запаса порог не ловится при быстрой прокрутке. Кнопка «Загрузить ещё» оставлена намеренно: она дублирует автозагрузку для клавиатуры и для тех, кто прыгнул к концу списка. Доля загруженного показана и числом, и полосой с role=progressbar и aria-valuenow: бесконечный список без дна дезориентирует. Шапка липнет сверху, поэтому колонки видны на любой глубине.

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 Datagrid025Row = {
  id: string
  time: string
  event: string
  source: string
  weight: number
}

export type Datagrid025Props = Omit<
  ComponentPropsWithoutRef<"section">,
  "children"
> & {
  rows?: Datagrid025Row[]
  caption?: string
  batchSize?: number
  accent?: string
}

// Идея компонента: длинный список догружается по мере прокрутки, но
// счётчик и кнопка остаются. Автозагрузка срабатывает у нижней кромки
// окна прокрутки, а «Загрузить ещё» дублирует её для клавиатуры и для
// тех, кто дошёл до низа рывком. Полоса прогресса показывает, сколько
// из общего числа уже подгружено — иначе бесконечный список не имеет дна.
const STYLES = `
:where([data-vibeui-block="datagrid-025"]){
--vibeui-datagrid-025-bg:oklch(1 0 0);
--vibeui-datagrid-025-fg:oklch(0.23 0.014 285);
--vibeui-datagrid-025-muted:oklch(0.55 0.014 285);
--vibeui-datagrid-025-border:oklch(0.92 0.006 285);
--vibeui-datagrid-025-head:oklch(0.975 0.003 285);
--vibeui-datagrid-025-accent:oklch(0.52 0.16 265);
--vibeui-datagrid-025-height:17rem;
--vibeui-datagrid-025-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="datagrid-025"]{
box-sizing:border-box;width:100%;max-width:48rem;margin:0 auto;
background:var(--vibeui-datagrid-025-bg);color:var(--vibeui-datagrid-025-fg);
border:1px solid var(--vibeui-datagrid-025-border);border-radius:0.875rem;
font-family:var(--vibeui-datagrid-025-font);overflow:hidden;
}
[data-vibeui-block="datagrid-025"] *{box-sizing:border-box}
[data-vibeui-block="datagrid-025"] [data-part="bar"]{
display:flex;flex-wrap:wrap;align-items:center;gap:0.5rem;
padding:0.75rem 0.875rem 0.625rem;border-bottom:1px solid var(--vibeui-datagrid-025-border);
}
[data-vibeui-block="datagrid-025"] [data-part="title"]{margin:0;font-size:0.875rem;font-weight:650;margin-inline-end:auto}
[data-vibeui-block="datagrid-025"] [data-part="count"]{margin:0;font-size:0.75rem;color:var(--vibeui-datagrid-025-muted)}
[data-vibeui-block="datagrid-025"] [data-part="track"]{
flex:0 0 100%;height:0.25rem;border-radius:999px;margin-top:0.125rem;
background:var(--vibeui-datagrid-025-border);overflow:hidden;
}
[data-vibeui-block="datagrid-025"] [data-part="fill"]{
display:block;height:100%;border-radius:999px;
width:var(--vibeui-datagrid-025-progress,0%);background:var(--vibeui-datagrid-025-accent);
transition:width .2s ease;
}
[data-vibeui-block="datagrid-025"] [data-part="scroll"]{
overflow:auto;max-height:var(--vibeui-datagrid-025-height);
}
[data-vibeui-block="datagrid-025"] [data-part="scroll"]:focus-visible{outline:2px solid var(--vibeui-datagrid-025-accent);outline-offset:-2px}
[data-vibeui-block="datagrid-025"] table{width:100%;border-collapse:separate;border-spacing:0;font-size:0.8125rem}
[data-vibeui-block="datagrid-025"] caption{
padding:0.625rem 0.875rem;text-align:left;font-size:0.75rem;color:var(--vibeui-datagrid-025-muted);caption-side:top;
}
[data-vibeui-block="datagrid-025"] th,
[data-vibeui-block="datagrid-025"] td{
padding:0.4375rem 0.875rem;text-align:left;white-space:nowrap;
border-bottom:1px solid var(--vibeui-datagrid-025-border);
}
[data-vibeui-block="datagrid-025"] thead th{
position:sticky;top:0;z-index:2;background:var(--vibeui-datagrid-025-head);font-weight:600;
}
[data-vibeui-block="datagrid-025"] [data-align="end"]{text-align:right;font-variant-numeric:tabular-nums}
[data-vibeui-block="datagrid-025"] [data-part="time"]{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:0.75rem;font-weight:500}
[data-vibeui-block="datagrid-025"] [data-part="source"]{color:var(--vibeui-datagrid-025-muted)}
[data-vibeui-block="datagrid-025"] [data-part="foot"]{
display:flex;align-items:center;justify-content:center;gap:0.5rem;
padding:0.625rem 0.875rem;border-top:1px solid var(--vibeui-datagrid-025-border);
}
[data-vibeui-block="datagrid-025"] [data-part="more"]{
appearance:none;cursor:pointer;font:inherit;font-size:0.75rem;font-weight:600;
padding:0.375rem 0.875rem;border-radius:0.5rem;
border:1px solid var(--vibeui-datagrid-025-accent);background:transparent;color:var(--vibeui-datagrid-025-accent);
}
[data-vibeui-block="datagrid-025"] [data-part="more"]:focus-visible{outline:2px solid var(--vibeui-datagrid-025-accent);outline-offset:2px}
[data-vibeui-block="datagrid-025"] [data-part="done"]{margin:0;font-size:0.75rem;color:var(--vibeui-datagrid-025-muted)}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="datagrid-025"] *{animation:none!important;transition:none!important}}
`

const SOURCES = ["касса-1", "касса-2", "терминал", "самовывоз", "маркетплейс"]
const EVENTS = [
  "Заказ оплачен",
  "Возврат оформлен",
  "Скидка применена",
  "Чек аннулирован",
  "Заказ собран",
  "Доставка назначена",
]

const DEFAULT_ROWS: Datagrid025Row[] = Array.from(
  { length: 48 },
  (_, index) => ({
    id: `l${index + 1}`,
    time: `12:${String(59 - index).padStart(2, "0")}`,
    event: EVENTS[index % EVENTS.length],
    source: SOURCES[index % SOURCES.length],
    weight: 120 + ((index * 37) % 880),
  }),
)

/**
 * Сетка с бесконечной прокруткой и счётчиком загруженного: порция
 * догружается у нижней кромки и по кнопке. Один файл, ноль зависимостей.
 */
export function Datagrid025({
  rows = DEFAULT_ROWS,
  caption = "Порция догружается у нижней кромки окна прокрутки",
  batchSize = 12,
  accent,
  className,
  style,
  ...props
}: Datagrid025Props) {
  const [shown, setShown] = useState(batchSize)

  const visible = rows.slice(0, shown)
  const done = shown >= rows.length
  const percent = Math.round((visible.length / rows.length) * 100)

  const palette = {
    "--vibeui-datagrid-025-progress": `${percent}%`,
    ...(accent ? { "--vibeui-datagrid-025-accent": accent } : null),
    ...style,
  } as CSSProperties

  function loadMore() {
    setShown((current) => Math.min(rows.length, current + batchSize))
  }

  return (
    <>
      <style href="vibeui-datagrid-025" precedence="medium">
        {STYLES}
      </style>
      <section
        {...props}
        data-vibeui-block="datagrid-025"
        className={className}
        style={palette}
      >
        <div data-part="bar">
          <h3 data-part="title">Лента событий кассы</h3>
          <p data-part="count" role="status" aria-live="polite">
            Загружено {visible.length} из {rows.length}
          </p>
          <span
            data-part="track"
            role="progressbar"
            aria-label="Доля загруженных строк"
            aria-valuenow={percent}
            aria-valuemin={0}
            aria-valuemax={100}
          >
            <span data-part="fill" />
          </span>
        </div>
        <div
          data-part="scroll"
          role="region"
          aria-label="Лента событий, прокручивается"
          tabIndex={0}
          onScroll={(event) => {
            const box = event.currentTarget

            if (
              !done &&
              box.scrollTop + box.clientHeight >= box.scrollHeight - 24
            ) {
              loadMore()
            }
          }}
        >
          <table>
            <caption>{caption}</caption>
            <thead>
              <tr>
                <th scope="col">Время</th>
                <th scope="col">Событие</th>
                <th scope="col">Источник</th>
                <th scope="col" data-align="end">
                  Сумма, ₽
                </th>
              </tr>
            </thead>
            <tbody>
              {visible.map((row) => (
                <tr key={row.id}>
                  <th scope="row" data-part="time">
                    {row.time}
                  </th>
                  <td>{row.event}</td>
                  <td data-part="source">{row.source}</td>
                  <td data-align="end">{row.weight.toLocaleString("ru-RU")}</td>
                </tr>
              ))}
            </tbody>
          </table>
        </div>
        <div data-part="foot">
          {done ? (
            <p data-part="done">Все {rows.length} строк загружены</p>
          ) : (
            <button type="button" data-part="more" onClick={loadMore}>
              Загрузить ещё {Math.min(batchSize, rows.length - shown)}
            </button>
          )}
        </div>
      </section>
    </>
  )
}