Undo setFormatter is missing or not explicit

Posted by: davide.vago on 16 January 2020, 10:52 pm EST

  • Posted 16 January 2020, 10:52 pm EST

    Good morning/afternoon

    I’m reaching you out as I’m currently trying to catch the ctrl+Z/cmd+Z shortcut during a setFormatter action.

    Let’s say: the user has a couple of buttons within the spreadsheet instance that permits to set a different format of a selection (percentage/financial)

    When the user clicks on the button and changes the formatter of a cell/selection, if the user presses CTRL+Z/CMD+Z the formatter doesn’t go back to his original.

    There is no way to track this as far as I understand, would you advise a solution for this issue?

    Thanks in advance for the support.

  • Posted 19 January 2020, 9:07 pm EST

    Hi Davide,

    To achieve the required functionality, it is recommended to add custom commands. For implementing the undo-redo functionality, you may use the startTransaction() and endTransaction() methods. Please refer to the following sample which demonstrates how we could add custom commands with undo/redo functionality and let us know if you face any issues:

    https://www.grapecity.com/spreadjs/demos/features/worksheet/custom-action/purejs

    Regards

    Sharad

  • Posted 22 January 2020, 5:00 am EST

    Thanks Sharad for coming back with this example,

    I’m currently struggling to understand how to implement it using the formatter, the fact is: this sample is based on a specific property which is the background colour. If I need to apply this on a list of buttons which are setting up different formats means I will have to create for each button a specific command.

    The solution seems a bit hacky and not really scalable.

  • Posted 22 January 2020, 4:40 pm EST

    You do not need to create a custom command for each button, you may simply make your command to accept the formatter option to apply and then just change the formatter options for each button. Please refer to the following sample which demonstrates the same:

    https://codesandbox.io/s/spread-js-starter-jizqo

  • Posted 7 April 2022, 2:41 am EST

    Hi,

    Apologies for the very late reply, I’m wondering if you could provide the sample applied to style as well (let’s say Bold/Italic) please.

    Your provided solution seems working pretty fine expect for the Undo/Redo via keyboard shortcuts don’t fire the execution of the custom command, but I believe it’s something related to the UndoManager (there is another post I recently posted about it)

  • Posted 7 April 2022, 9:10 pm EST

    Hi Davide,

    Please refer to the following updated sample which has custom action for bold and italic styles.

    sample: https://codesandbox.io/s/spread-js-starter-forked-9t0kst?file=/index.html

    Regards,

    Avinash

Need extra support?

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

Learn More

Forum Channels