Posted 21 October 2020, 5:23 pm EST
I want to edit not overwrite the content. Spread v13. Google Sheets uses return/enter. Excel with F2. Can I get Spreadjs to use “return/enter” like google sheets?
Forums Home / Spread / SpreadJS
Posted by: jeff on 21 October 2020, 5:23 pm EST
Posted 21 October 2020, 5:23 pm EST
I want to edit not overwrite the content. Spread v13. Google Sheets uses return/enter. Excel with F2. Can I get Spreadjs to use “return/enter” like google sheets?
Posted 22 October 2020, 11:07 pm EST
Hi Jeff,
You may create the custom Command for the required functionality and set it to the f2 Key. Please refer to the following code snippet and the attached sample that demonstrates the same.
var command = {
canUndo: true,
execute: function (spread, options, isUndo) {
var Commands = GC.Spread.Sheets.Commands;
if (isUndo) {
Commands.undoTransaction(spread, options);
return true;
} else {
Commands.startTransaction(spread, options);
spread.suspendPaint();
sheet.startEdit();
spread.resumePaint();
Commands.endTransaction(spread, options);
return true;
}
}
};
var commandManager = spread.commandManager();
commandManager.register("f2", command);
commandManager.setShortcutKey("f2", 113, false, false, false, false);
sample: https://codesandbox.io/s/silly-dijkstra-itmdj?file=/src/index.js:191-823
API references:
customAction Demo: https://www.grapecity.com/spreadjs/demos/features/worksheet/actions/custom-action#demo_source_name
Regards
Avinash
Posted 23 October 2020, 2:32 am EST
Avinash, Awesome. How would I make the enter key (Code 13) work? How would I make it toggle on and off like google sheets?
Posted 25 October 2020, 10:32 pm EST
Hi Jeff,
You may use isEditing method and implement your own custom action on the enter key. Please refer to the following code snippet and the attached sample that demonstrates the same.
var command = {
execute: function (spread, options, isUndo) {
let sheet = spread.getActiveSheet();
if (!sheet.isEditing()) {
sheet.startEdit();
return true;
} else {
return false;
}
}
}
var commandManager = spread.commandManager();
commandManager.register("enter", command);
//13 is key code of enter
commandManager.setShortcutKey("enter", 13, false, false, false, false);
sample: https://codesandbox.io/s/adoring-mestorf-hhyw2?file=/src/index.js:171-610
API References:
isEditing: https://www.grapecity.com/spreadjs/docs/v13/online/SpreadJS~GC.Spread.Sheets.Worksheet~isEditing.html?highlight=isediting%2C
customAction: https://www.grapecity.com/spreadjs/demos/features/cells/hyperlink/custom-command#demo_source_name
Regards
Avinash