Undo with keyboard

Tags: #<Tag:0x00007f8b184ffce0>

Hi,

I’m changing the background color of the cells whenever the user make any changes to the data in the respective cell. This is working fine with afterChange() event.

Now when the user revert the changes by pressing ‘Ctrl+Z’ (Undo), the data should be reverted to old data and the background color should also be removed. How can i remove the background color during the Undo operation? Any suggestions will be helpful…

Hey @prasanth.sivakumar

you can keep a copy of your data and check if the changed cell has the same value as the original one and then use instance.setCellMeta(row, column).className = ""

In case i change multiple cells and hit undo multiple times, the changes should be reverted one by one… Can i get the row and column index in afterUndo event? Otherwise how can i get the row and col index of the row where the undo operation is applied?

Hey @prasanth.sivakumar

the afterChange hook fires on undo/redo. Then the 2nd parameter is UndoRedo.undo

https://jsfiddle.net/handsoncode/y1f7artx/1/

Hi Aleksanra,

When i copy data to multiple cells with dragdown, and then perform an Undo operation, the afterchange event is fired only once and not for all the changed columns. In that case how can we get the index of all cells changed with Undo? Appreciate your help.

Can you record it, please? I’ll proceed with the same steps and check what we’re missing to track down the values.

Aleksandra,

Please try this https://jsfiddle.net/oLkz6j4p/38/

You may type in some data into any cell, it will highlight the cell (yellow). Now drag down the data from this cell to multiple cells (say to 5 cells). Now if you press Undo, the afterchange event is fired only once, not for all 5 cells… Hope it is clear…

The afterChange hook lets you know how many cells have been changed and it works for the autofill as well. If the changes are made for more than 1 cell then the length of the changes array is longer than 1.