Posted 22 February 2018, 11:49 pm EST
Is there some way add setStyle action into Undo queue?
For now even in demo on your site it’s impossible to undo an action of setting cell to a bold or italic font style for example.
Forums Home / Spread / SpreadJS
Posted by: my.mail.kharkov on 22 February 2018, 11:49 pm EST
Posted 22 February 2018, 11:49 pm EST
Is there some way add setStyle action into Undo queue?
For now even in demo on your site it’s impossible to undo an action of setting cell to a bold or italic font style for example.
Posted 28 February 2018, 9:23 pm EST
Hello,
We could observe the mentioned behaviour at our end. Unfortunately, we could not find a direct way of adding the “setStyle” action to the Undo queue.
We have escalated the issue to the development team for further discussion. We will let you know as soon as the investigation completes. The tracking ID for this issue is 255073.
We regret the inconvenience caused.
Thanks,
Manpreet Kaur
Posted 6 March 2018, 8:52 pm EST
Hello,
Currently, Spread supports the built-in undo/redo operation only for the commands listed here: http://help.grapecity.com/spread/SpreadSheets11/webframe.html#SpreadJS~GC.Spread.Sheets.Commands.html. Hence, it does not undo the style action performed on the sheet.
You would need to register the setStyle method as a custom command in Spread, so as to add the setStyle action into Undo queue. Please refer to the following documentation link, which describes how you can register a custom command to Spread: http://help.grapecity.com/spread/SpreadSheets11/webframe.html#SpreadJS~GC.Spread.Commands.CommandManager~register.html.
Here is the sample code to register the setStyle command for setting the cell style to bold and italic and later undo the operation by using the Ctrl+Z shortcut key:
spread.commandManager().register(‘setCellBoldStyle’, {
canUndo: true,
execute: function (context, options, isUndo) {
var sheet = context.getSheetFromName(options.sheetName);
if (isUndo) {
sheet.setStyle(options.row, options.col, options._oldStyle);
} else {
options._oldStyle = sheet.getStyle(options.row, options.col);
sheet.setStyle(options.row, options.col, options.boldStyle);
}
}
}, null, false, false, false, false);
spread.commandManager().register('setCellItalicStyle', { canUndo: true, execute: function (context, options, isUndo) { var sheet = context.getSheetFromName(options.sheetName); if (isUndo) { sheet.setStyle(options.row, options.col, options._oldStyle); } else { options._oldStyle = sheet.getStyle(options.row, options.col); sheet.setStyle(options.row, options.col, options.italicStyle); } } }, null, false, false, false, false);
Kindly refer to the attached sample(UndoStyle.zip) which implements the above code and is working as expected. You can click on the buttons displayed on top of Spread to set the style of the current cell to bold or italic. Later, when you press the Ctrl+Z shortcut key, it removes the style set on the cell.
Hope it helps.
Thanks,
Manpreet KaurUndoStyle.zip
Posted 17 January 2022, 1:44 am EST
With SpreadJS 14 is it still a thing? Cause on REDO the SetStyle event is called but on not on UNDO.
Posted 18 January 2022, 9:35 pm EST
Hi,
We are sorry but currently Spread supports the built-in undo/redo operation only for the commands listed here: https://www.grapecity.com/spreadjs/docs/v14/online/SpreadJS\~GC.Spread.Sheets.Commands.html
Hence, it does not undo the style action performed on the sheet.
As mentioned earlier in this post, You would need to register the setStyle method as a custom command in Spread, so as to add the setStyle action into Undo queue.
Please refer to this demo on defining a custom command which supports undo/redo functionality.https://www.grapecity.com/spreadjs/demos/features/worksheet/actions/custom-action#demo_source_name
Regards