Spread.Sheets Documentation
Using Undo and Redo
Spread.Sheets Documentation > Developer's Guide > Managing the User Interface > Using Undo and Redo

You can use Ctrl + Z to undo an action in the widget. You can then use Ctrl + Y to redo the action you canceled.

You can undo the following types of actions:

The following actions do not respond to Ctrl + Z:

You can prevent or allow the undo action in code with the options.allowUndo property.

After setting the allowUndo property to true, you can undo or redo an action by using the startTransaction() method, undoTransaction() method and the endTransaction() method.

Using Code

This example sets the options.allowUndo property and specifies an action.

JavaScript
Copy Code
spread.options.allowUndo = true;
spread.commandManager().execute({cmd: "outlineRow", sheetName: activeSheet.name(), index: 3, count: 5});

This example changes the background color of a cell using the startTransaction() method, undoTransaction() method and the endTransaction() method.

JavaScript
Copy Code

var command = { canUndo: true, execute: function (context, options, isUndo)

                { var Commands = GC.Spread.Sheets.Commands;
                  if (isUndo)

                  {
                     Commands.undoTransaction(context, options);
                     return true;
                  }

                    else

                  {
                    Commands.startTransaction(context, options);
                    var sheet = context.getSheetFromName(options.sheetName);
                    var cell = sheet.getCell(options.row, options.col);
                    cell.backColor(options.backColor);
                    Commands.endTransaction(context, options);
                    return true;
                   } 

                 }
                };
var spread = GC.Spread.Sheets.findControl(document.getElementById("sampleDiv"));
var commandManager = spread.commandManager();
commandManager.register("changeBackColor", command);
commandManager.execute({ cmd: "changeBackColor", sheetName: spread.getSheet(0).name(), row: 1, col: 2, backColor: "red" }); 

See Also