Finding the value of the row before the changes in afterChange

Tags: #<Tag:0x00007efc620536a0>

Hi HOT Community,

I’d like to show the differences in a row before and after a number of cells are edited. As an example if you have a row numbered ‘7’ of 5 cells, all cells have values a,b,c,d,e,f and you drag-select a,b,c and press delete I want to be able to show a diff:

Row: 7
Change made: a,b,c,d,e,f

In afterChange or even beforeChange I can’t get the value of the row before the change was made. The only solution I have at the moment seems to be keeping my own copy of the entire data model for HOT, which sounds inefficient. Does anyone have a better idea?

I have a debounce setup at ~500ms so that I can capture multiple cell changes as just one ‘row change’. I could really painfully try and back off all the change deltas from the new row value, but that also sounds painful.

Whilst I was waiting i’ve accomplished this with a debounce and a state variable that accumulates oldValues for a given ‘changeset’ and then plays them back over the final row value (fetched in the debounce) to derive original row value. Not ideal, but works. Please do tell me if there’s a much nicer way I could have used.

Hi @HC289

Can you share your latest progress? In the theory, the beforeChange should be a perfect choice. But I may be misunderstanding the use case.

Hi Aleksandra, thanks for getting back to me.

beforeChange has a list of changes for the cell

But I want the old value for the row. If I try and fetch the row value from my hotTable.getDataAtRow(rowNumber) in beforeChange I think it was already updated. If that sounds wrong I can go back and look again. It could be that instead of ‘stepping backwards’ in afterChange I could store the initial row value in beforeChange to send off later (after a debounce indicates to me this is the only cell on that row being altered).

I’m building a ‘track changes’ feature, so below the main HotTable people can see a list of changes to rows e.g. 'row 5 at 11:10AM, John added values ‘blah’, ‘bleh’, ‘foo’ and removed ‘ragno’ (which i’m displaying with a strikethrough). LMK if i’m missing a simple plugin for that :smiley:

Ahhh yea. I can see what you mean now. True, you’d need a deep clone https://jsfiddle.net/AMBudnik/frd4tg07/ cause otherwise data is changed by reference. Or even that way https://jsfiddle.net/AMBudnik/pyv0c1u2/ cause it does not call the parse method with each change.

Hi @HC289

how’s the progress?

The debounce method worked and as I’m on a deadline I’ve just left it there for now! Thanks for checking in.

I’m accumulating old values, then stepping back the final row value in the debounce and then using that as my ‘old row value’ reference point

Great. Thank you for your feedback.
If there’s anything left we can make a short call to discuss it over. I’m available between 8-3:30 CET