Posted 4 April 2023, 4:06 am EST
I want to custom function for all features in the context menu delete Dialog, I can’t register a new command for “Designer.deleteLeftCells”,… Can you help me?
Forums Home / Spread / SpreadJS
Posted by: ngodinhvuluan on 4 April 2023, 4:06 am EST
Posted 4 April 2023, 4:06 am EST
I want to custom function for all features in the context menu delete Dialog, I can’t register a new command for “Designer.deleteLeftCells”,… Can you help me?
Posted 4 April 2023, 5:48 am EST - Updated 4 April 2023, 7:07 am EST
When I set custom command for
[ ‘gc.spread.contextMenu.deleteColumns’,
‘gc.spread.contextMenu.deleteRows’,
‘Designer.deleteLeftCells’,
‘Designer.deleteUpCells’ ],
this work if I execute by ribbon, but I open ‘delete Dialog’ by context menu and my custom command was init to default action of SpreadJS, how can I hold it?
Posted 5 April 2023, 11:43 pm EST
Hello,
As per my understanding, you want to execute your custom command instead of default command when the “Shift Cells Left” option is selected in the Delete dialog as well as from the ribbon.
For this use case, you can create a custom command and register the custom command with “Designer.deleteLeftCells” name to override the default command. You can use commandManager.register() method to register a command on command manager.
Please refer to the code snippet and attached sample.
let commandManager = spread.commandManager();
// creates a custom command
let command = {
canUndo: true,
execute: function (context, options, isUndo) {
var Commands = GC.Spread.Sheets.Commands;
options.cmd = "Designer.deleteLeftCells";
if (isUndo) {
Commands.undoTransaction(context, options);
return true;
} else {
Commands.startTransaction(context, options);
let sheet = context.getSheetFromName(options.sheetName);
sheet.setValue(options.activeRowIndex, options.activeColIndex, 'deleteLeftCells command');
Commands.endTransaction(context, options);
return true;
}
}
};
commandManager.register("Designer.deleteLeftCells", command);
Please let us know if you still face any issues.
Doc references:
commandManager.register(): https://www.grapecity.com/spreadjs/api/v15/classes/GC.Spread.Commands.CommandManager#register
spread.commandManager():https://www.grapecity.com/spreadjs/api/v16/classes/GC.Spread.Sheets.Workbook#commandmanager
Regards,
Ankit
Posted 6 April 2023, 12:53 am EST
Thanks to help me!