This page covers a non-latest version of Handsontable.
# CopyPaste
# Description
This plugin enables the copy/paste functionality in the Handsontable. The functionality works for API, Context Menu, using keyboard shortcuts and menu bar from the browser. Possible values:
true(to enable default options),false(to disable completely).
or an object with values:
'columnsLimit'(see CopyPaste#columnsLimit)'rowsLimit'(see CopyPaste#rowsLimit)'pasteMode'(see CopyPaste#pasteMode)'uiContainer'(see CopyPaste#uiContainer).
See the copy/paste demo for examples.
Example
// Enables the plugin with default values
copyPaste: true,
// Enables the plugin with custom values
copyPaste: {
columnsLimit: 25,
rowsLimit: 50,
pasteMode: 'shift_down',
uiContainer: document.body,
},
# Options
# copyPaste
Source code (opens new window)copyPaste.copyPaste : object | boolean
The copyPaste option configures the CopyPaste plugin.
You can set the copyPaste option to one of the following:
| Setting | Description |
|---|---|
true (default) | Enable the CopyPaste plugin with the default configuration |
false | Disable the CopyPaste plugin |
| An object | - Enable the CopyPaste plugin- Modify the CopyPaste plugin options |
If you set the copyPaste option to an object, you can set the following CopyPaste plugin options:
| Option | Possible settings | Description |
|---|---|---|
columnsLimit | A number (default: Infinity) | A maximum number of columns that can be copied |
rowsLimit | A number (default: Infinity) | A maximum number of columns that can be copied |
pasteMode | 'overwrite' | 'shift_down' | 'shift_right' | When pasting:'overwrite': overwrite currently-selected cells'shift_down': move currently-selected cells down'shift_right': move currently-selected cells to the right |
uiContainer | An HTML element | A UI container for the secondary focusable element |
Read more:
Default: true Example
// disable the `CopyPaste` plugin
copyPaste: false,
// enable the `CopyPaste` plugin
// and modify the `CopyPaste` plugin options
copyPaste: {
// set the maximum number of columns that can be copied
columnsLimit: 25,
// set the maximum number of rows that can be copied
rowsLimit: 50,
// set the paste behavior
pasteMode: 'shift_down',
// set the UI container
uiContainer: document.body,
},
# Members
# columnsLimit
Source code (opens new window)copyPaste.columnsLimit : number
Maximum number of columns than can be copied to clipboard using CTRL + C.
Default: Infinity
# pasteMode
Source code (opens new window)copyPaste.pasteMode : string
Defines paste (CTRL + V) behavior.
- Default value
"overwrite"will paste clipboard value over current selection. - When set to
"shift_down", clipboard data will be pasted in place of current selection, while all selected cells are moved down. - When set to
"shift_right", clipboard data will be pasted in place of current selection, while all selected cells are moved right.
Default: "overwrite"
# rowsLimit
Source code (opens new window)copyPaste.rowsLimit : number
Maximum number of rows than can be copied to clipboard using CTRL + C.
Default: Infinity
# uiContainer
Source code (opens new window)copyPaste.uiContainer : HTMLElement
UI container for the secondary focusable element.
# Methods
# copy
Source code (opens new window)copyPaste.copy()
Copies the selected cell into the clipboard.
# cut
Source code (opens new window)copyPaste.cut()
Cuts the selected cell into the clipboard.
# destroy
Source code (opens new window)copyPaste.destroy()
Destroys the plugin instance.
# disablePlugin
Source code (opens new window)copyPaste.disablePlugin()
Disables the plugin functionality for this Handsontable instance.
# enablePlugin
Source code (opens new window)copyPaste.enablePlugin()
Enables the plugin functionality for this Handsontable instance.
# getRangedCopyableData
Source code (opens new window)copyPaste.getRangedCopyableData(ranges) ⇒ string
Creates copyable text releated to range objects.
| Param | Type | Description |
|---|---|---|
| ranges | Array<object> | Array of objects with properties startRow, endRow, startCol and endCol. |
Returns: string - Returns string which will be copied into clipboard.
# getRangedData
Source code (opens new window)copyPaste.getRangedData(ranges) ⇒ Array<Array>
Creates copyable text releated to range objects.
| Param | Type | Description |
|---|---|---|
| ranges | Array<object> | Array of objects with properties startRow, startCol, endRow and endCol. |
Returns: Array<Array> - Returns array of arrays which will be copied into clipboard.
# isEnabled
Source code (opens new window)copyPaste.isEnabled() ⇒ boolean
Checks if the plugin is enabled in the handsontable settings. This method is executed in Hooks#beforeInit
hook and if it returns true than the CopyPaste#enablePlugin method is called.
# paste
Source code (opens new window)copyPaste.paste(pastableText, [pastableHtml])
Simulates the paste action.
| Param | Type | Default | Description |
|---|---|---|---|
| pastableText | string | Value as raw string to paste. | |
| [pastableHtml] | string | "" | optional Value as HTML to paste. |
# setCopyableText
Source code (opens new window)copyPaste.setCopyableText()
Prepares copyable text from the cells selection in the invisible textarea.
# updatePlugin
Source code (opens new window)copyPaste.updatePlugin()
Updates the plugin state. This method is executed when Core#updateSettings is invoked.