I want to copy all table data with headers to excel. I saw in the docs that ctrl+shift+space is the shortcut for this job. Sadly, the shortcut doesn’t do anything for me. Ctrl+a works, but copies only table data (without headers). What could be the issue?
I use handsontable version 13.1.0. I have no code the mingles with keyboard shortcuts, and my handsontable code initiation is simple.
hot = new Handsontable(container, {
data: data,
columns: columns,
rowHeaders: true,
colHeaders: colHeaders,
manualColumnResize: colWidthsOrdered,
renderer: function (instance, td, row, col, prop, value) {
Handsontable.renderers.TextRenderer.apply(this, arguments);
if (value != null) {
td.innerHTML = `<div class="text-truncate"">${value}</div>`;
}
},
dropdownMenu: ["filter_by_condition", "filter_action_bar", "filter_by_value"],
filters: true,
allowRemoveRow: true,
contextMenu: ["row_below", "copy_with_column_headers"],
copyPaste: {
copyColumnHeaders: true,
},
hiddenColumns: {
columns: hiddenColumns,
},
columnSorting: true,
outsideClickDeselects: false,
afterChange: function (changes, source) { ... },
});
Debugging following code shows that variable selectDataWithHeadersShortcut is empty. If i use [“ctrl”, “a”], the variable is not empty. Does this mean that ctrl+shift+space shortcut does not exist, even though it’s mentioned in the docs?
const gridContext = hot.getShortcutManager().getContext('grid');
const selectDataWithHeadersShortcut = gridContext.getShortcuts([
"control/meta",
"shift",
"space",
]);
I’m confused now. I tried copy pasting the code from the docs, but undoShortcut is empty list:
const gridContext = hot.getShortcutManager().getContext('grid');
const undoShortcut = gridContext.getShortcuts(['control/meta', 'z']);
Not sure if I’m doing something wrong, or docs are outdated.
Hi @kragelj.valentin
Thank you for contacting us. I understand that it might be a little confusing so let me clarify things.
Enabling the copyColumnHeaders
in the plugin configuration will only enable it as an option for the context menu. It won’t affect any keyboard shortcuts. So for you requirements if you want to copy all cells and all headers you will need to enable it from plugin method API level. Here’s an example: Handsontable example - JSFiddle - Code Playground
Now if you use CTRL/CMD + A it will select the whole table and all cells with the column headers will be copied.
Thanks @adrian.szymanski! What about I select only some cells (i.e. C4, C5, D4 and D5 in your example app), how can I copy that together with headers, using ctrl+c ctrl+v?
What about keyboard shortcuts, shouldn’t that work out of the box?
@kragelj.valentin
It will work only for non-consecutive selection. As for the keyboard shortcuts, it works correctly and if you select the whole table this way it will also copy the column headers: Handsontable example - JSFiddle - Code Playground
Thanks, looks like I need to take a deeper dive into our code to see why shortcuts don’t work.