Why does this happen
Cause as we can see here Handsontable example - JSFiddle - Code Playground our data is connected by reference. When we log the data (via button) before doing any changes we get
but once we change anything in the table (example: change ‘4’ to ‘xyz’) our variable that represents the data changes
You cannot break the reference, but if you wish to hold the original data you can create a deep copy via JSON.stingify().
When source stays the same
When we use formulas like here Handsontable example - JSFiddle - Code Playground the getDataAtCell returns the value of the formula and getSourceDataAtCell returns the syntax of the formula.
afterChange for filtered data
the afterChange is not triggered when we filter data. Can you share some details about this scenario? May I assume that you want to get the index of the rows that remain after filtering the those that refer to the original index before the filtering?
My data was in this format: [ { name: 'Leo', age: 34 ...}, { name: 'Ale', age: 34 ...} ]
I understand that this format isn’t good for HT so I’m switching to array of arrays [ ['Leo', 34, ...],['Ale', 34, ...] ]
In this cases modifies are working as expected!
So, Answer#1 is NO, the way is array of arrays if I need to modify it.
Can you share some details about this scenario? May I assume that you want to get the index of the rows that remain after filtering the those that refer to the original index before the filtering?
Yes, your guess was correct, because I needed to manually update the data, but I solved ( Answer#2) it by changing the data format.
Answer#3 I didn’t know that jsfiddle supports Angular 2+, thanks !
there’s nothing wrong with the array of objects. If that is what you get from the server you should not switch to an array of arrays.
Here’s Handsontable example - JSFiddle - Code Playground a demo with the array of objects data. I’ve added a call to the indexMapper within the afterFilter callback. When you open the console you’ll see the whole description of the filtering action that just took place.
Example
I filter out everything and just keep Person_3 and Person_4
By the first line, I am informed that I have 2 rows, where the row with index 2 moved to index 0, and row with index 3 moved to index 1.
Then you have a similar info in the notTrimmedIndexesCache where you get the info that the row index 2 and row index 3 are visible in the table.
Answer#3 I didn’t know that jsfiddle supports Angular 2+, thanks !
We try to support a new version of Angular as soon as it’s there for the developer to use.
If you’d have any further questions feel free to contact me at support@handsontable.com. And if you have a list of requirements that haven’t been cleared yet I’m also open to a call to discuss them over.