Spread undo redo in async functioins

Posted by: lior.sharabi on 26 October 2022, 9:02 am EST

  • Posted 26 October 2022, 9:02 am EST

    Hi

    I’m trying to implement the undo/redo like i saw in the documentation:

    https://www.grapecity.com/spreadjs/docs/features/worksheet/undo

    In your documentation example, for setting commands in the same undo/redo transaction i need to put them between “commands.startTransaction(context, options);” and “commands.endTransaction(context, options);”

    in our system we have async flows, it means that i want to insert commands from before the async call and after it returns to the same transaction .

    For example, i may want to put commands into transaction A through an async call, and while waiting for the call back add commands to transaction B in a different flow, when the async call return i want to add more commands to transaction A.

    is it possible?

    const cell : GC.Spread.Sheets.CellRange;
    const cell2 : GC.Spread.Sheets.CellRange;
    const command = {
    		canUndo: true,
    		execute: (context: GC.Spread.Sheets.Workbook, options: any, isUndo: boolean) => {
    			const commands = gcModule.Spread.Sheets.Commands;
    			if (isUndo) {
    				commands.undoTransaction(context, options);
    				return true;
    			} else {
    				commands.startTransaction(context, options);
    
    				cell.value("value")
    				setTimeout(() => {
    					cell2.value("value2")
    				}, 200)
    
    				commands.endTransaction(context, options);
    				return true;
    			}
    		},
    	};
    	const commandManager = gcModule.workbook.commandManager();
    	commandManager.register("id", command);
    	commandManager.execute({ cmd: "id", sheetName });

    Thanks Lior

  • Posted 28 October 2022, 4:55 am EST

    Hello Lior,

    According to my understanding, you want to run async actions within the Custom command you’ve created.

    Because the execute method is asynchronous, you can use the await keyword to wait for the async action to complete.

    You can use the following sample that I created: https://jscodemine.grapecity.com/share/jHBKBwFloEWF5XSbMHyVxQ/

    If you have a different use case, please let us know. Could you also elaborate on your use case with an example so that we have a better understanding of it and can assist you accordingly?

    execute method: https://www.grapecity.com/spreadjs/api/classes/GC.Spread.Commands.CommandManager#execute

    Regards,

    Ankit

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels