[GH #1516] Keyboard shortcuts not working

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.

I am bumping my own thread because I’ve found a bug/strange behavior.

@adrian.szymanski in your jsfiddle example, copying with headers only works the first time. Every time after the first one, it will not copy headers.

Example:
select cell ‘A1’ → ctrl+c → ctrl+v in text editor → pasted text is ‘A A1’. Go back to jsfiddle, ctrl+c again → ctrl+v in text editor → pasted text is ‘A1’. Header (‘A’) was not copied.

Another thing is if I select random cells (e.g. A1, B2, C3) and use ctrl+c ctrl+v, only the last cell is copied (in this case C3). I tried this in @adrian.szymanski jsfiddle. Why aren’t all cells copied?

Hi @kragelj.valentin

I was able to reproduce the first issue you mentioned and I will report it internally. As for the second one I was unable to get the same results. Please share exact steps and/or video recording.

Thank you. I’m guessing the first issue is a bug and will take time to get fixed?

For the second issue, here are the steps:

Only ‘C1’ will be pasted. Expected result would be both cells to be copied (A1 and C1).

For second issue, copying headers is not important, but related to “copy paste does not copy all selected non-consequential cells”.

@kragelj.valentin

Yes, it has to be fixed at the core and I will update you once it’s done. As for the second issue I already explained that it’s not supported here: [GH #1516] Keyboard shortcuts not working - #6 by adrian.szymanski

Right, thought you meant “It [= copying with headers] will work only for non-consecutive selection”. Didn’t know you meant copying in general.

Thanks for your help, for now I will use beforeCopy hook for the first issue.

@kragelj.valentin

Yes, I meant copying in general. Sorry for the confusion.

1 Like