RowCopyPaste
Allow using [Ctrl/CMD + C/X] and [Ctrl/CMD + V] to copy/cut-and-paste rows. Also makes cut, copy and paste actions available via the cell context menu.
You can configure how a newly pasted record is named using generateNewName
This feature is enabled by default
const grid = new Grid({
features : {
rowCopyPaste : true
}
});
//<code-header>
fiddle.title = 'Row copy paste';
//</code-header>
targetElement.innerHTML = '<p>Copy/cut and paste rows using keyboard shortcuts or context menu:</p>';
// grid with basic configuration
const grid = new Grid({
// makes grid as high as it needs to be to fit rows
autoHeight : true,
appendTo : targetElement,
columns : [
{ field : 'name', text : 'Name' },
{ field : 'job', text : 'Job', renderer : ({ value }) => value || 'Unemployed' }
],
data : [
{ id : 1, name : 'Bill', job : 'Retired' },
{ id : 2, name : 'Elon', job : 'Visionary' },
{ id : 3, name : 'Me' }
]
});This feature will work alongside with CellCopyPaste but there is differences on functionality.
- Context menu actions, and keyboard shortcuts, will be processed by either feature depending on what is selected and
where the context menu was triggered. Set rowOptionsOnCellContextMenu to
trueto show two sets of options when context menu is triggered on a selected cell. - They share clipboard, so even when the internal clipboard is used, it is not possible to have rows and cells copied or cut at the same time.
Keyboard shortcuts
The feature has the following default keyboard shortcuts:
| Keys | Action | Weight ¹ | Action description |
|---|---|---|---|
Ctrl+C |
copy | 10 | Calls copyRows which copies selected row(s) into the clipboard. |
Ctrl+X |
cut | 10 | Calls copyRows which cuts out selected row(s) and saves in clipboard. |
Ctrl+V |
paste | 10 | Calls pasteRows which inserts copied or cut row(s) from the clipboard. |
¹ Customization of keyboard shortcuts that has a weight can affect other features that also uses that
particular keyboard shortcut. Read more in our guide.
Ctrl is the equivalent to Command and Alt
is the equivalent to Option for Mac usersFor more information on how to customize keyboard shortcuts, please see our guide.
Configs
20
Configs
20Other
If true, this translates copy actions to cut actions and removes the context menu Copy option.
The field to use as the name field when updating the name of copied records
Adds Cut (row), Copy (row) and Paste (row) options when opening a context menu on a selected cell when
cellSelection and
CellCopyPaste is active. Default behaviour will only provide row copy/paste actions on a
selected row.
Misc
Properties
18
Properties
18Common
Class hierarchy
Functions
31
Functions
31Common
Copy or cut selected rows to clipboard to paste later
| Parameter | Type | Description |
|---|---|---|
isCut | Boolean | Copies by default, pass |
Paste rows below selected or passed record
| Parameter | Type | Description |
|---|---|---|
record | Model | Paste below this record, or currently selected record if left out |
Pasted records
Configuration
Events
Misc
Other
Events
9
Events
9Fires on the owning Grid before a copy action is performed, return false to prevent the action
// Adding a listener using the "on" method
rowCopyPaste.on('beforeCopy', ({ source, records, isCut, entityName }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Grid | Owner grid |
records | Model[] | The records about to be copied |
isCut | Boolean |
|
entityName | String | 'row' to distinguish this event from other beforeCopy events |
Fires on the owning Grid before a paste action is performed, return false to prevent the action
// Adding a listener using the "on" method
rowCopyPaste.on('beforePaste', ({ source, referenceRecord, records, originalRecords, isCut, entityName, data }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Grid | Owner grid |
referenceRecord | Model | The reference record, the clipboard event records will be pasted above this record |
records | Model[] | The records about to be pasted |
originalRecords | Model[] | For a copy action, these are the records that were copied.
For cut action, this is same as the |
isCut | Boolean |
|
entityName | String | 'row' to distinguish this event from other beforePaste events |
data | Model[] | String | The clipboard data (Model instances or raw string) |
Fires on the owning Grid after a copy action is performed.
// Adding a listener using the "on" method
rowCopyPaste.on('copy', ({ source, originalRecords, records, isCut, entityName }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Grid | Owner grid |
originalRecords | Model[] | The records that were copied |
records | Model[] | The new record copies. If this is a cut action, this will be the same
record instances as |
isCut | Boolean |
|
entityName | String | 'row' to distinguish this event from other copy events |
Fires on the owning Grid after a paste action is performed.
// Adding a listener using the "on" method
rowCopyPaste.on('paste', ({ source, referenceRecord, records, originalRecords, isCut, entityName }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Grid | Owner grid |
referenceRecord | Model | The reference record, below which the records were pasted |
records | Model[] | Pasted records |
originalRecords | Model[] | For a copy action, these are the records that were copied.
For a cut action, this is same as the |
isCut | Boolean |
|
entityName | String | 'row' to distinguish this event from other paste events |
Event handlers
9
Event handlers
9Called on the owning Grid before a copy action is performed, return false to prevent the action
new RowCopyPaste({
onBeforeCopy({ source, records, isCut, entityName }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Grid | Owner grid |
records | Model[] | The records about to be copied |
isCut | Boolean |
|
entityName | String | 'row' to distinguish this event from other beforeCopy events |
Called on the owning Grid before a paste action is performed, return false to prevent the action
new RowCopyPaste({
onBeforePaste({ source, referenceRecord, records, originalRecords, isCut, entityName, data }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Grid | Owner grid |
referenceRecord | Model | The reference record, the clipboard event records will be pasted above this record |
records | Model[] | The records about to be pasted |
originalRecords | Model[] | For a copy action, these are the records that were copied.
For cut action, this is same as the |
isCut | Boolean |
|
entityName | String | 'row' to distinguish this event from other beforePaste events |
data | Model[] | String | The clipboard data (Model instances or raw string) |
Called on the owning Grid after a copy action is performed.
new RowCopyPaste({
onCopy({ source, originalRecords, records, isCut, entityName }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Grid | Owner grid |
originalRecords | Model[] | The records that were copied |
records | Model[] | The new record copies. If this is a cut action, this will be the same
record instances as |
isCut | Boolean |
|
entityName | String | 'row' to distinguish this event from other copy events |
Called on the owning Grid after a paste action is performed.
new RowCopyPaste({
onPaste({ source, referenceRecord, records, originalRecords, isCut, entityName }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Grid | Owner grid |
referenceRecord | Model | The reference record, below which the records were pasted |
records | Model[] | Pasted records |
originalRecords | Model[] | For a copy action, these are the records that were copied.
For a cut action, this is same as the |
isCut | Boolean |
|
entityName | String | 'row' to distinguish this event from other paste events |