Handsontable - afterChange ordinal position changes on sort

Hi,
I am using the afterChange event to update the dataset one row at a time. This works well provided the dataset stays in the same order as the load.

The issue that I run into is that the afterChange passes an ordinal position for the row in the “change” set, if the user has sorted the rows, they are no longer in the same order as the original load. So I have no way to find which record I should update.
and example :

on load the data row would be {“data”:[[6,“budget”,43446,’’]]}

after sort {“data”:[[4,“budget”,43446,’’]]}

Is there a way to inject an id into the change data object so I can identify the correct record?

Kindest Regards,
Allen Cordrey

Hi Allen,

in Handsontable we have an ability to work on physical and visual indexes.

Can you share a demo with the following solution? I am not sure if I understand how it works.

Sure, Here is a a jsfiddle of what I am trying to do:

http://jsfiddle.net/WP_Acordrey/h4e9x47t/4/

basically, I need a way to properly identify the change dataset the afterchange returns based on something other than the ordinal position.

an example take customer 1005 for 2017 and change sales target from empty to 3000 the returned data on the afterchange looks like this:

“data”:[[4,“budget”,"",3000]]

now sort the grid by company, find 1005 for 2017 and change the sales target from 3000 to 4000

the data comes back as “data”:[[2,“budget”,3000,4000]

So I have no unique identifier based on this data.

Regards,
Allen

Hi @acordrey

haven’t we been talking about the same example on Github board or on emails? I have got the same demo and case a few days ago. Unfortunately, I cannot find it in my system.

Hi,
No this is my first post. Is there a better way to get the elements of the changed data?

Thanks,
Allen

Oh, then sorry. I guess that I must have seen something similar.

Can you share an example of an expected result as well? The result array of the afterChange hook maybe be less than expected but as we have triggered the change and got a result we can gather a little bit more information from the action.

Is there a way to return the entire data row on the onchange event? I don’t necessarily need the delta of the change but the row itself so I can get the unique ID of the changed row so I can update it in our database

Please let me know if that is hat you were looking for http://jsfiddle.net/qxt3vz3z/

That was what I needed, thank you

Great. Feel free to open new topics if needed.