bc-grid
GitHub

CSV export

View source

streamServerGridToCsv walks the grid's loadPage page-by-page, formats each row through the column's valueFormatter, and emits CSV string chunks. No server-side renderer required.

100,000 rows behind the loader.
Order #
Customer
Amount
Status
Sales rep
Region
Opened
Loading

Try this

The export walks all 100,000 rows in 500-row pages.

  • Click Export to CSV; the file downloads when the walk finishes.
  • Apply a sort or search before exporting — the export honours the active view (sort + filter + search round-trip into getExportPlan().view).
  • Toggle a column off via the column-visibility menu — it's excluded from the export.
  • The progress counter ticks each page; for a real export, this drives a UI progress bar.

The contract

  • getExportPlan(). Imperative API on BcServerGridApi. Returns BcExportPlan with the active view, visible columns, headers, and a per-cell formatter that mirrors what the grid renders.
  • streamServerGridToCsv. Stateless helper. Takes { plan, loadPage, pageSize?, onChunk, onProgress?, signal? }. Walks pages from index 0; emits a header row + one chunk per row. Returns total rows + pages loaded.
  • No buffering. Chunks stream out as the loader yields rows, so memory stays flat. For very large exports, pipe onChunk into a streaming download (WritableStream / File System Access API) instead of accumulating to a string.
  • AbortSignal. Pass a signal to support cancel-mid-export. The signal is forwarded to each loadPage call.

What's NOT here

  • Excel / XLSX export — out of scope for @bc-grid/export; pair getExportPlan() with ExcelJS on your end.
  • Server-rendered exports — for bandwidth-sensitive flows, prefer shipping the export plan to your server and streaming back pre-formatted rows.
  • Pivot exports — the pivoted shape exports as a flat matrix using the same plan; the demo above is non-pivoted.