Posted 24 October 2019, 12:27 pm EST
The keystroke command + a in Excel selects the entire sheet’s cells. How do I make spreadJS do this?
Forums Home / Spread / SpreadJS
Posted by: jeff on 24 October 2019, 12:27 pm EST
Posted 24 October 2019, 12:27 pm EST
The keystroke command + a in Excel selects the entire sheet’s cells. How do I make spreadJS do this?
Posted 25 October 2019, 2:21 am EST
Hi Jeff,
We could support this functionality by adding a custom command using commandManager.register() method. Please refer to the following code snippet and the sample demonstrating the same:
function registerSelectAllCommand(spread) {
var commandManager = spread.commandManager();
var selectAllCommand = {
canUndo: false,
execute: function(wbContext, options, isUndo) {
let sheet = wbContext.getSheetFromName(options.sheetName);
sheet.setSelection(0, 0, sheet.getRowCount(), sheet.getColumnCount());
return true;
}
};
commandManager.register(
"selectAllCommand",
selectAllCommand,
GC.Spread.Commands.Key.a,
true,
false,
false,
false
);
}
https://codesandbox.io/s/spread-js-starter-q8o00
Regards
Sharad
Posted 26 October 2019, 12:26 am EST
Sharad,
Great but on Mac all commands are done using the “command/apple Key” not “control”. Can you switch your solution to using the command key for Apple devices?
Jeff
Learn more here.
https://stackoverflow.com/questions/3902635/how-does-one-capture-a-macs-command-key-via-javascript
Posted 28 October 2019, 8:34 am EST
Hi Jeff,
You could set the meta option to true to bind a shortcut to command key, please refer to the following code snippet:
commandManager.register(
"selectAllCommandCmd",
selectAllCommand,
GC.Spread.Commands.Key.a,
false, // true for ctrl
false, // true for shift
false, // true for alt
true // true for meta, uses the Command key on the Macintosh or the Windows key on Microsoft Windows
);
API reference: http://help.grapecity.com/spread/SpreadSheets12/webframe.html#SpreadJS~GC.Spread.Commands.CommandManager~register.html