Posted 11 November 2021, 8:21 pm EST
Hi,
For enabling the undo for custom action. You need to create a custom command. Please refer to the following code snippet and demo that explains the basic use of custom action.
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();
var selections = options.selections;
var value = options.backColor;
selections.forEach(function(sel) {
sheet.getRange(sel.row, sel.col, sel.rowCount, sel.colCount).backColor(value);
});
spread.resumePaint();
Commands.endTransaction(spread, options);
return true;
}
}
};
var selections = sheet.getSelections();
var commandManager = spread.commandManager();
commandManager.register('changeBackColor', command);
commandManager.execute({
cmd: 'changeBackColor',
sheetName: spread.getSheet(0).name(),
selections: selections,
backColor: 'rgb(130, 188, 0)'
});
Demo: https://www.grapecity.com/spreadjs/demos/features/worksheet/actions/custom-action#demo_source_name
Regards
Avinash