Copy and paste
Select cells and press Ctrl+C, and the text pastes straight into Excel or Google Sheets. Values copied from Excel paste into grid cells with Ctrl+V. The keyboard, the context menu and code (copyCells, cutCells, pasteCells) all follow the same rules.
Try it in the gallery example Copy and paste in editable cells and the example Copy selected cells as tab-separated text.
Choose the cells to copy
The cells to copy are picked in this order.
- The
rangeyou pass in code - The last selected cell range
- The focused cell, if there is no range
To select several cells, turn on cellSelection. It defaults to 'none', so only one cell at a time is copied.
createGrid(el, {
columns,
rows,
rowKey: 'id',
cellSelection: 'multiple', // 'single' is one cell, 'multiple' is many cells and ranges
});In 'multiple' mode, drag with the mouse, or click a cell and extend with Shift+click or Shift+arrow keys, and add a range with Ctrl+click (⌘+click on a Mac). You can also select in code with api.selectCells(from, to). Sorting, filtering or grouping clears the selection.
Keyboard and menu
| Action | Key | Context menu |
|---|---|---|
| Copy | Ctrl+C (⌘+C on a Mac) | Copy |
| Copy with headers | Copy with headers | |
| Cut | Ctrl+X | Cut |
| Paste | Ctrl+V | Paste |
| Fill down, fill right (1.4.0) | Ctrl+D, Ctrl+R |
Ctrl+D and Ctrl+R work only when cellFill is on (Fill handle). The keyboard alternative to dragging a cell range with cellDrag (Drag a cell range) is cut and paste.
Pressing Ctrl+V on a selected cell is the most reliable way to paste. Depending on the browser, the menu's Paste needs permission to read the clipboard, and a notice appears if it is blocked (Cell context menu). In text inputs, cells being edited, or while text is selected by dragging, the browser handles the keys itself.
Copy selected rows
When a grid uses only row selection (selection) and no cell range, copyCells() and Ctrl+C copy the selected rows. All visible columns are joined with tabs, and the lines follow the screen order (after sort and filter). Header options such as header: 'columns' work as they do for ranges.
- Priority: the
rangeoption, then the selected cell range (cellSelection), then the selected rows, then the focused cell. cutCells()with only rows selected clears nothing and returns an empty string. Copying rows never erases values.
What gets copied
- The text shown on screen. A cell displayed as
4,200,000 KRWthroughformatValueis copied with that text, not the raw value. - Cells are separated by tabs and rows by line breaks. A value containing a tab, a line break or a double quote is wrapped in double quotes so Excel reads it correctly.
- Hidden columns are left out and the screen order is kept. Rows are the visible rows after sorting and filtering.
- Group rows and summary rows are skipped. Only data rows are included.
You can add headers in front. In code this is the header option.
header | Lines added in front |
|---|---|
'none' | None. The default |
'columns' | The column titles |
'groups' | The group title lines, then column titles |
Use it in code
const text = api.copyCells(); // the selected range, or the focused cell
const withTitles = api.copyCells({ header: 'columns' });
const part = api.copyCells({
range: { from: { rowKey: 1, columnId: 'name' }, to: { rowKey: 3, columnId: 'dept' } },
});
api.cutCells(); // returns the same text as copyCells and clears those cells
const report = api.pasteCells('Dev\t3500000\nDesign\t3200000');
// { pasted: 4, skipped: 0 }copyCells and cutCells only return the text. They do not write to the clipboard, so call navigator.clipboard.writeText(text) yourself if you need that. The keyboard (Ctrl+C, X) and the menu do write to the clipboard.
pasteCells starts at the top-left cell of the selected range, or at the focused cell if there is no range. Set the start cell with at.
api.pasteCells(text, { at: { rowKey: 5, columnId: 'salary' } });If the text is a single value and you did not pass at, the value fills the whole selected range. It works like copying one cell in Excel and pasting into many.
Cells that paste skips
Paste writes each cell exactly like a manual edit. Validation (validation), the editCommitted event and change tracking all run as usual. These cells are skipped and counted in skipped.
- Cells that cannot be edited (
editableis off, or the row is blocked by a condition) - Cells whose text cannot be converted to the column type, such as
abcin a number column or non-date text in a date column - Cells that fail edit validation
- The whole paste, if some cell is being edited right now
Text is converted by column type as follows.
| Cell type | Rule |
|---|---|
| Text | Used as is |
| Number | Commas are removed before reading. An empty text means no value |
| Date | Only text that reads as a date. An empty text means no value |
| Checkbox | true, 1, yes and similar are true. false, 0, no and an empty text are false |
| Select | Must match an option's label or value |
Parts that fall outside the table are dropped silently. They are not counted in skipped, and neither are positions that land on group or summary rows.
Cut uses the same path. It pastes empty text over the selected cells, so cells that cannot be edited are left as they are.
Value formats and paste
If the column has parse, text and number cells pass the pasted text to parse as it is. A throw or undefined skips that cell. A format.date.stored column also reads loose dates such as 2026/05/06 and writes the stored shape (see Columns).
Get the result: cellsPasted
Every time a paste or cut finishes, the cellsPasted event reports { pasted, skipped }. Calling pasteCells in code returns the same values.
api.on('cellsPasted', ({ pasted, skipped }) => {
status.textContent =
skipped === 0 ? `Pasted ${pasted} cells.` : `Pasted ${pasted} cells, skipped ${skipped}.`;
});pasted counts cells whose value actually changed. A cell pasted with the same value is not counted.
A paste is one undo step
After pasting or cutting several cells, one Ctrl+Z restores all of them. You do not undo cell by cell. Ctrl+Y puts the whole paste back. Undo works on grids that use editing (Cell editing).
A grid without the editing feature cannot write values, so paste changes nothing and every cell counts as skipped. Copy still works.
Set it with an option: clipboard
The clipboard option changes the defaults of copy and paste. Omitted keys keep the previous behavior.
createGrid(el, {
columns,
rows,
clipboard: { delimiter: ';', copyAs: 'value', addRows: true },
});| Key | Value | Default | Meaning |
|---|---|---|---|
delimiter | one character | tab | Separates cells on copy and is read on paste. Not a quote or newline |
copyAs | 'text', 'value' | 'text' | Display text or the stored raw value |
paste | boolean | true | false blocks paste and removes the menu item |
cut | boolean | true | false blocks cut and removes the menu item |
addRows | boolean | false | Lines past the last row are added as new rows |
With paste or cut set to false, calling pasteCells or cutCells throws invalid-option. Copy always works.
You can also override per call: copyCells({ as: 'value' }), pasteCells(text, { addRows: true }). copyRows(keys, options) copies rows by key regardless of the selection.
Fine-tune with columns and hooks
- Column
copyValue({ value, row, rowKey, columnId })decides the copied text (nullis empty). It is not used withas: 'value'. - Column
pasteable: falseskips that cell on paste and counts it inskipped. Cut still clears it. - Hooks
beforeCopyandbeforeCutveto withfalse;copyCellandcopyHeaderreplace text.beforePastevetoes withfalseor returns new text;pasteCellreplaces one cell's text. - Events
copyStarted,cutStartedandpasteStartedcome before the work;cellsCopiedandcellsPastedcome after.
Paste lines as new rows
With addRows on, lines past the last row become new rows, and added in the result is how many. The new row's key must come from the pasted values per the rowKey rule. A missing or duplicate key throws and nothing changes. The new rows and the cell values undo together with one Ctrl+Z.