Could we undo(via ctrl+z) if we change data with setSourceDataAtCell?

Tags: #<Tag:0x00007f8b2b1734b0> #<Tag:0x00007f8b2b172cb8>

We have some functionality that replace multiple cell using setSourceDataAtCell (we need to use this function because we need to update data that is hidden via hiddenRows or hideColumns).

Seems like we can not undo (ctrl+z) changed data via setSourceDataAtCell. Do we have any workaround or do I need to provide some configuration to make it works?

Hi @elecwebmaker

You are right the setSourceDataAtCell is not on the actions list for the undoRedo plugin.

However, you said that you use it as you want ot alter values in a hidden part of the table. But setDataAtCell also seems to work well there. Here’s a little demo that I made. https://stackblitz.com/edit/vitejs-vite-mi3q29?file=main.js,counter.js,style.css&terminal=dev

I put a value via setDataAtCell() in coordinates 1, 1 and use hiddenRows to guide row index 1 and the same for columns on index 1. Stil, the value is there (we can use contextMenu to show it, and we have the getData() logged via beforeUndo.

Sorry, I said it wrong. I means via filtered row (filter plugin) that the row index is changed and hidden(filtered( row have no visual row index. So we can not use setDataAtCell because it accept visual row index

I see, yes, And as I understand, you would get getSourceData() on the filtered table? If so, you are right that is currently not supported with the undo.

I guess that you could create undo action for that in your context/dropdown menu, but I am not sure if that would meet your project requirements.

@aleksandra_budnik
I mean currently we have button for update all cell values that match some certain criteria. It also need to change both for not filtered cell and filtered cell.

After user update the cell via button, they want also to undoable via ctrl + z. For manual change (editing cell manually) it works fine with handsontable, but when we update cell values via setSourceDataAtCell(), user can not undo it via ctrl +z. Do we have any solution for this?

I know setDataAtCell doesn’t have this problem. but we can’t use it because we can not update value for filtered cell. So we need to use setSourceDataAtCell which can update all data even though it’s filtered or not.

There is no API to add setSourceDataAtCell to the actions supported by undoRedo plugin. But maybe you can create your custom logic for the undo keyboard combination. To do that check the ShortcutManager API. Then you can track CTRL/CMD + Z shortcut and re-change the data once again with the setSourceDataAtCell.

@aleksandra_budnik

I think it’s tricky or almost impossible to do this our own because if we create our own changes stack, there’re two changes stack. 1 for our own stack and second is handsontable changes stack. We are unable to sync both stacks.

Let’s say

  • change manual (handsontable stack)
  • change via setSourceDataAtCell (our own stack)
  • change manual (handsontable stack)
  • change manual (handsontable stack)

we unable to know which one should we pop and use it for undo (pop from handsontable or pop from our own stack).

Yes, that would make more sense to block the undoRedo entirely and provide your own undo stack with row_index, prop, old value.