I am using Handsontable spreadsheet control with php and data saved in mongodb. When copy paste a bunch of data on control, 'afterChage' event triggers with source as 'paste'. Inside this i am trying to update a value (RowID) on a particular cell (0) using the function instance.setDataAtCell(rowIndex, 0, vRowId)
afterChange: function(changes, source) {
console.log('Trigrd>>');
console.log('Source:'+source);
console.log('Changes:'+changes);
if (source == 'paste' || source == 'autofill' || (changes.length >1 )) {
var minVal = changes[0][0];
var maxVal = changes[chLength][0];
for(var modifyRowIndex = minVal; modifyRowIndex <= maxVal ;modifyRowIndex++){
var xrowId = Math.random();
instance.setDataAtCell(modifyRowIndex, 0, xrowId, 'program');
}
}
}
if i try to paste two row data on spreadsheet, on console we can see that the afterChange function is triggered 3 times.
Trigrd>>
Source:paste
Changes:[[0,1,'','xxxx'],[1,1,'','yyyy']]
Trigrd>>
Source:edit
Changes:[0,0,'','1232']
Trigrd>>
Source:edit
Changes:[1,0,'','23434']
The first trigger is for the action 'paste' and remaining two trigger is due to the command 'setDataAtCell'. This makes a delay on total copyPaste action. Some times it stuck with large data copyPaste
Anybody have any idea to skip the 'edit' loop here.
If you are still looking for a solution I think this one will help you.
I had a problem like yours and I managed to resolve it by making modifications on beforeChange
and not in afterChange
:
beforeChange : function(changes, source){
if (source == 'paste'){
var nrChanges = changes.length;
for (var i = 0; i < nrChanges; i++)
if (changes[i][1] == _CB) // get cell where you want to control
changes[i][3] = false; // here you add your value
}
}
and on afterChange
you will get the values you set it ...