@bsuite/data-grid

中文文档
3.0.5发布于 2026/10/21UNLICENSEDTypeScriptES Module近 30 天下载 2077

Virtualized, spreadsheet-feel data grid for BSuite apps — cell range selection, keyboard grid navigation, TSV clipboard round-trip, fill handle, undo/redo. Built on @tanstack/react-table + @tanstack/react-virtual.

原始使用文档
文档目录4 节
  1. Partial persistence outcomes
  2. Retrying a retained draft
  3. Implementation and verification bounds
  4. Per-cell edit restrictions

@bsuite/data-grid

Partial persistence outcomes

onCellsEdited still accepts synchronous or asynchronous void (every cell succeeded). A host that saves a batch independently can return CellEditResult:

<DataGrid
  data={rows}
  columns={columns}
  getRowId={(row) => row.id}
  onCellsEdited={async (edits) => {
    const failures: CellEditFailure[] = [];
    for (const edit of edits) {
      try {
        await saveCell(edit.rowId!, edit.columnId, edit.value);
      } catch (error) {
        retainRetryDraft(edit); // Host-owned draft, separate from the grid's data.
        failures.push({
          rowId: edit.rowId!,
          columnId: edit.columnId,
          status: 'failed',
          message: error instanceof Error ? error.message : undefined,
        });
      }
    }
    return { failures };
  }}
  onError={showSaveError}
/>

Import CellEditFailure and CellEditResult from @bsuite/data-grid. Every edit emitted by the grid includes rowId; the field remains optional in CellEdit for compatibility with existing host-created objects. Match outcomes using rowId and columnId, never the current display index. getRowId must return unique, stable record identifiers when rows can be reordered or filtered. The legacy index fallback cannot identify records across a host data reorder.

Each omitted cell is successful. Failures require status: 'failed'; message is optional and defaults to “Failed to save the edit.” Unknown or duplicate identities invalidate the result and report the submitted cells as failed; the host must refresh before retrying an uncertain write. Rejecting the callback continues to mean the whole batch failed. A partial saver must therefore return the actual failed subset instead of throwing after some writes have succeeded. Each applyCells (or retry) call resolves with the receipt for that exact invocation, even if a newer attempt later supersedes one or more of its cells.

Failed optimistic values are removed and the corresponding cells show their refusal message. Host data/refetch controls their displayed value; discarding a host retry draft cannot leave a hidden grid overlay behind. Successful overlays remain until host data acknowledges that value, then release so later server updates are visible. The host must update or invalidate its authoritative data on persistence. A fresh edit clears that cell's old refusal.

Undo contains only successful cells. Partial undo and redo move successful cells to the opposite history and retain refused cells on their original side for retry. An unavailable row is refused locally instead of sending a write to the record now occupying its former index. A pending save can be undone; its late completion cannot replace the newer overlay or undo history.

Per-cell ownership protects grid state, not database write ordering. Hosts must serialize same-cell writes (including undo/redo) or use server conditional writes. A UI ownership check cannot cancel an already-running database update. When a host serializes whole batches, capture its promise queue outside render, chain each batch onto it, and recover the queue's rejection without converting a failed batch into success. Keep latest-attempt ownership for host draft/error state as well. onError receives only currently owned failed cells; it does not report stale failures belonging to an older attempt.

Retrying a retained draft

Use gridRef.current.applyCells([{ rowId, columnId, value }]) with the already typed values from failed CellEdits. It rebinds each identity to the current row and uses the same refusal, persistence and undo pipeline as direct editing. The promise settles after persistence outcomes are handled; inspect the host draft store for any remaining failures. Missing/duplicate identities reject before any write. Do not call the host persistence callback directly for retry: that would leave grid refusal and history state disconnected from the save.

All value mutations, including paste/fill/clear/undo/retry, require an explicitly editable column. Linked fields must use their supplied record picker and the link mutation callback; a pasted label is never a record reference.

Implementation and verification bounds

This extends the existing grid and undo stack; no replacement engine or new dependency is used. Stable identity follows the installed TanStack Table 9.2.4 table_getRowId implementation (custom extractor, otherwise string index), confirmed with Context7 and the installed package's dist/core/rows/coreRowsFeature.utils.js. See the official TanStack row identity guide. The alternative of retaining failed optimistic drafts inside the grid loses refetch/discard authority and was rejected; retry editing belongs to the host.

Mounted tests exercise actual grid keyboard paste, mixed failures, refetch, undo/redo, reorder/filter, no-op/void behavior, and overlapping completions. ui_touched=true: the consumer rollout remains open across the 23 existing CRM render sites, the new Conduit Candidates surface, and other estate consumers. Package tests do not establish deployed UX acceptance. Consumer wiring, preview publication/pinning, and the parent's D8/live verification remain required.

Per-cell edit restrictions

Stable 3.0.5 finalises the published 3.0.5-next.0 source without a runtime change. Development consumers use the preview artifact for deployed UX testing; stable publication and consumer adoption remain separate release steps. This parent source integration does not update any app lockfile. Follow the preview publishing standard.

Use isCellEditable={(row, columnId) => !row.imported} for authoritative rows that must remain read-only inside an otherwise editable grid. This optional, pure, synchronous predicate only restricts editing: columns still require editable: true, and linked fields still require their existing record picker. Omitting it preserves column-only editability.

The predicate receives the latest host row, without optimistic values. It controls mouse/keyboard editor entry and aria-readonly, paste/clear/fill targets, and the mutation boundary for retry/undo/redo. Protected targets are skipped before parsing or optimistic display during paste/fill/clear; TSV positions are preserved, so values never shift into a different row. Explicit applyCells and history operations return normal per-cell refusal receipts for currently protected cells. Eligible manual siblings in a mixed batch still save. Selection, navigation and copy remain available; a wholly read-only selection has no fill handle. Mixed selections retain the handle, but protected destination cells remain unchanged.

Open editors follow stable row/column identity and visual coordinates through reorder; permissions are checked again at commit. If their row or column disappears, the grid cancels the invisible edit, reports that no edit was saved through onError, and restores keyboard input. Queued undo rechecks current policy after waiting for its predecessor. Hosts must retain their own server and mutation guards: this API prevents impossible UI edits and does not provide database authorization.

The alternative of disabling an entire grid would prevent work on manual rows; consumer event interception would duplicate mutation rules across mouse, keyboard, clipboard and history. One shared predicate keeps those paths consistent. The mounted regression covers both frozen/scrollable cells, linked pickers, mixed mutation ranges and policy changes during active editor/clipboard/history work. Accessibility follows the WAI-ARIA grid pattern.

版本与发布记录

@bsuite/data-grid 共发布 26 个版本,首次发布于 2026/08/07;过去 12 个月发布了 26 个版本。

版本发布日期距今
3.0.5latest2026/10/2119 天前
3.0.5-next.1next2026/10/2119 天前
3.0.5-next.02026/10/011 个月前
3.0.42026/09/181 个月前
3.0.4-next.22026/09/091 个月前
3.0.4-next.12026/09/091 个月前

关于 @bsuite/data-grid 的常见问题

@bsuite/data-grid 是什么?

Virtualized, spreadsheet-feel data grid for BSuite apps — cell range selection, keyboard grid navigation, TSV clipboard round-trip, fill handle, undo/redo. Built on @tanstack/react-table + @tanstack/react-virtual.

如何安装 @bsuite/data-grid?

在项目目录运行 npm install @bsuite/data-grid,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^19.0.0)、react-dom(^19.0.0)、@tanstack/react-table(^9.2.4)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@bsuite/data-grid 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@bsuite/data-grid 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@bsuite/data-grid 可以商用吗?

@bsuite/data-grid 使用 UNLICENSED 许可。作者声明为 UNLICENSED,即不授予公开使用许可(与公共领域的 Unlicense 不同)。使用前需获得作者授权。以上为概括,不构成法律意见,请以许可原文为准。

@bsuite/data-grid 的下载量有多少?

根据 npm 官方下载统计,@bsuite/data-grid 在 2026/10/09 – 2026/11/07 这 30 天内被下载 2,077 次,日均约 69 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bsuite/data-grid 还在维护吗?

最新版本 3.0.5 发布于 2026/10/21(19 天前);至今共发布 26 个版本,其中过去 12 个月发布了 26 个;首次发布于 2026/08/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。