Skip to content

ClipboardPlugin

Clipboard Plugin for tbw-grid

Brings familiar copy/cut/paste functionality with full keyboard shortcut support (Ctrl+C, Ctrl+X, Ctrl+V). Handles single cells, multi-cell selections, and integrates seamlessly with Excel and other spreadsheet applications via tab-delimited output.

> Optional Dependency: Works best with SelectionPlugin for copying/pasting selected > cells. Without SelectionPlugin, copies the entire grid and pastes at row 0, column 0.

import { ClipboardPlugin } from '@toolbox-web/grid/plugins/clipboard';
OptionTypeDefaultDescription
includeHeadersbooleanfalseInclude column headers in copied data
delimiterstring'\t'Column delimiter (tab for Excel compatibility)
newlinestring'\n'Row delimiter
quoteStringsbooleanfalseWrap string values in quotes
processCell(value, field, row) => string-Custom cell value processor
pasteHandlerPasteHandler | nulldefaultPasteHandlerCustom paste handler
ShortcutAction
Ctrl+C / Cmd+CCopy selected cells
Ctrl+V / Cmd+VPaste into selected cells
Ctrl+X / Cmd+XCut selected cells
Selection TypePaste Behavior
Single cellPaste expands freely from that cell
Range selectionPaste is clipped to fit within the selected range
Row selectionPaste is clipped to the selected rows
No selectionPaste starts at row 0, column 0
MethodSignatureDescription
copy(options?: CopyOptions) => Promise<string>Copy to clipboard with optional column/row control
copyRows(indices, options?) => Promise<string>Copy specific rows to clipboard
paste() => Promise<string[][] | null>Read and parse clipboard content
getSelectionAsText(options?: CopyOptions) => stringGet clipboard text without writing to clipboard
getLastCopied() => { text, timestamp } | nullGet info about last copy operation
import '@toolbox-web/grid';
import { ClipboardPlugin } from '@toolbox-web/grid/plugins/clipboard';
import { SelectionPlugin } from '@toolbox-web/grid/plugins/selection';
grid.gridConfig = {
columns: [
{ field: 'name', header: 'Name' },
{ field: 'email', header: 'Email' },
],
plugins: [
new SelectionPlugin({ mode: 'range' }),
new ClipboardPlugin({
includeHeaders: true,
delimiter: '\t', // Tab for Excel
}),
],
};
new ClipboardPlugin({
pasteHandler: (grid, target, data) => {
// Validate or transform data before applying
console.log('Pasting', data.length, 'rows');
return defaultPasteHandler(grid, target, data);
},
})

Extends BaseGridPlugin

Inherited methods like attach(), detach(), afterRender(), etc. are documented in the base class.

Get the text representation of the current selection (or specified data) without writing to the system clipboard.

Useful for previewing what would be copied, or for feeding the text into a custom UI (e.g., a “copy with column picker” dialog).

getSelectionAsText(options: CopyOptions): string
NameTypeDescription
optionsCopyOptionsControl which columns/rows to include

string - Delimited text, or empty string if nothing to copy

const clipboard = grid.getPluginByName('clipboard');
const text = clipboard.getSelectionAsText({
columns: ['name', 'email'],
includeHeaders: true,
});
console.log(text);
// "Name\tEmail\nAlice\talice@example.com\n..."

Copy data to the system clipboard.

Without options, copies the current selection (or entire grid if no selection). With options, copies exactly the specified columns and/or rows — ideal for “copy with column picker” workflows where the user selects rows first, then chooses which columns to include via a dialog.

copy(options: CopyOptions): Promise<string>
NameTypeDescription
optionsCopyOptionsControl which columns/rows to include

Promise<string> - The copied text

const clipboard = grid.getPluginByName('clipboard');
await clipboard.copy();

Copy specific rows by index to clipboard.

Convenience wrapper around copy for row-based workflows. Supports non-contiguous row indices (e.g., [0, 3, 7]).

copyRows(indices: number[], options: Omit<CopyOptions, "rowIndices">): Promise<string>
NameTypeDescription
indicesnumber[]Array of row indices to copy
optionsOmit<CopyOptions, rowIndices>Additional copy options (columns, headers, etc.)

Promise<string> - The copied text

const clipboard = grid.getPluginByName('clipboard');
// Copy only rows 0 and 5, including just name and email columns
await clipboard.copyRows([0, 5], { columns: ['name', 'email'] });

Read and parse clipboard content.

paste(): Promise<string[][] | null>

Promise<string[][] | null> - Parsed 2D array of cell values, or null if clipboard is empty


Get the last copied text and timestamp.

getLastCopied(): object | null

object | null - The last copied info or null


AI assistants: For complete API documentation, implementation guides, and code examples for this library, see https://raw.githubusercontent.com/OysteinAmundsen/toolbox/main/llms-full.txt