Clipboard
NextGrid supports RFC-style quoted TSV copy, cut, paste, and delete through keyboard shortcuts (Ctrl/Cmd+C, X, V, Delete/Backspace), the body context menu, and programmatic APIs.
import { Grid, type ColumnDef } from 'next-grid-js';import { createOrders, type OrderRow } from './data/orders';import { syncGridTheme } from './theme';import type { DemoMountContext } from './types';import { addButton } from './ui';
export function mount({ stage, controls, meta,}: DemoMountContext): () => void { const columnDefs: readonly ColumnDef<OrderRow>[] = [ { key: 'id', name: 'ID', width: 96, }, { key: 'customer', name: 'Customer', width: 170, flex: 1, isEditable: true, }, { key: 'quantity', name: 'Qty', width: 85, cellDataType: 'number', isEditable: true, }, { key: 'status', name: 'Status', width: 110, isEditable: true, }, ];
const grid = new Grid<OrderRow>({ container: stage, columnDefs, rowData: createOrders(25), getRowId: (row) => row.id, cellSelection: { mode: 'range' }, clipboard: { copyMode: 'formatted', maxCells: 5000, }, fill: { showHandle: true, maxCells: 1000, }, history: { maxEntries: 50 }, }); const stopTheme = syncGridTheme(stage);
grid.setCellRange( { row: { displayIndex: 0 }, colId: 'customer', }, { row: { displayIndex: 1 }, colId: 'quantity', }, );
let undoBtn!: HTMLButtonElement; let redoBtn!: HTMLButtonElement; const syncHistory = () => { const h = grid.getHistoryState(); undoBtn.disabled = !grid.canUndo(); redoBtn.disabled = !grid.canRedo(); meta.textContent = `Undo: ${h.undoCount} · Redo: ${h.redoCount}`; }; grid.addEventListener('historyChanged', syncHistory);
undoBtn = addButton(controls, 'Undo', () => grid.undo(), { disabled: true, }); redoBtn = addButton(controls, 'Redo', () => grid.redo(), { disabled: true, }); addButton(controls, 'Fill down (Qty)', () => { grid.fillCells( { start: { row: { displayIndex: 0 }, colId: 'quantity', }, end: { row: { displayIndex: 0 }, colId: 'quantity', }, }, { start: { row: { displayIndex: 0 }, colId: 'quantity', }, end: { row: { displayIndex: 3 }, colId: 'quantity', }, }, ); }); syncHistory();
return () => { grid.destroy(); stopTheme(); };}ClipboardOptions & Programmatic API
Section titled “ClipboardOptions & Programmatic API”| Option | Type | Default | Description |
|---|---|---|---|
copyMode |
'formatted' | 'raw' |
'formatted' |
Whether Ctrl/Cmd+C copies formatted cell text or raw values |
maxCells |
number |
50000 |
Maximum cells allowed per copy/paste operation |
maxTextLength |
number |
1000000 |
Maximum TSV character length |
const tsv = grid.getClipboardText({ raw: true });await grid.copyToClipboard({ raw: false });await grid.cutToClipboard();grid.pasteFromText('Acme\t42');await grid.pasteFromClipboard();grid.deleteSelectedCells();Visual Feedback & Browser Permissions
Section titled “Visual Feedback & Browser Permissions”- Highlights: Keyboard and
bodyMenucopy/cut/paste highlight affected cells with.grid-cell-copiedor.grid-cell-pastedfor800 ms(static outline underprefers-reduced-motion: reduce), surviving row recycling by logical cell identity. Programmatic API calls do not show visual highlights. - Live Status & Paste Permissions:
.grid-clipboard-status(role="status") announces copied/pasted counts, rejections, and shows a 4-secondCtrl+V/⌘Vhint if browser security blocks clipboard read from a menu click.