Suppose you have a hook like so… you want to prepend some text, or alter the value completely, after it makes it into the cell (I actually wish I could do this on beforeChange, or that there was some format function).
const myAfterChangeHook = (changes, source) =>
if(source === "MyHook") return;
for (const [row, col, original, updated] of changes) {
hotTable.setDataAtRowProp(row, col, "Change: " + updated, "MyHook");
}
}
Then you have some other hook listening for changes, basically to see if the data in the table has changed ever.
const myHookListener = (changes, source) =>
// This will log two events in this order
// [0, 0, "value", "Change: value"], "MyHook"
// [0, 0, "", "value"], "edit"
console.log(changes, source);
}
This is surprising because the actual order of changes was
“” → “value” → “Change: value”
But it is not reported like this
This is a problem for me specifically because this hook is seeing if data in the cell has changed. It does this by storing a history. Now it thinks that the original value was “value” and the new value is “value”, and thus determines the change was undone.
Is there a workaround here, or is there a way to change the value before it hits the cell, like beforeChange or preformatData or similar? Maybe a way to change the priority of hooks…
Thanks.