Posted 5 June 2025, 1:44 am EST
- Updated 5 June 2025, 1:49 am EST
Hi,
It is possible to perform undo/redo operations using Ctrl+Z/Y on the data set programmatically in the SpreadJS cells using SpreadJS Command Manager: https://developer.mescius.com/spreadjs/api/classes/GC.Spread.Commands.CommandManager by wrapping your logic inside a custom command.
This ensures that changes made to adjacent or related cells are tracked correctly and included in the undo/redo stack.
const commandManager = spread.commandManager();
const setAdjacentColumnCommand = {
canUndo: true,
execute: function (context, options, isUndo) {
const Commands = GC.Spread.Sheets.Commands;
options.cmd = "setAdjacentColumn";
if (isUndo) {
Commands.undoTransaction(context, options);
return true;
} else {
Commands.startTransaction(context, options);
const sheet = context.getSheetFromName(options.sheetName);
sheet.suspendPaint();
sheet.setValue(options.row, options.col, options.data);
sheet.resumePaint();
Commands.endTransaction(context, options);
return true;
}
}
};
commandManager.register("setAdjacentColumn", setAdjacentColumnCommand);
You may also refer to the attached code sample, which demonstrates the implementation of the above snippet and successfully replicates the desired undo/redo behavior (see below).
Sample: https://jscodemine.mescius.io/share/aMXACc-AV0eiK2l2ebOYQQ/?defaultOpen={"OpenedFileName"%3A["%2Findex.html"%2C"%2Fapp.js"]%2C"ActiveFile"%3A"%2Fapp.js"}
GIF: 
Please feel free to reach out if you require any additional assistance.
Regards,