edit() API not working in for loop
edit() API not working in for loop

How come edit() API doesn't work in a for loop..? It only works on the first loop but doesn't get processed afterwards.
navigator.clipboard.readText().then(text => {
var cell = tableEditable.cell({ focused: true });
if (!cell.index()) return;
var rowIndex = cell.index().row;
var columnIndex = cell.index().column;
var arrayRows = text.split("\n");
arrayRows.forEach(element => {
var array = element.split("\t");
var data = new Object();
var cIndex = columnIndex;
array.forEach(value => {
var column = $(tableEditable.column(cIndex++).header()).text();
data[column] = value;
});
var row = tableEditable.row(rowIndex++);
editor.edit(row, false).set(data).submit();
});
});
For example, if text = 'CI-SEA\t07-31 22:00\nKE-SEA\t08-08 22:00;'
, below are console.log(data) values:
data in first loop => {REF: "CI-SEA", PU: "07-31 22:00"}
data in second loop => {REF: "KE-SEA", PU: "08-08 22:00"}
The first data is saved at the right positions, but the second data is gone...nowhere to be found...even ajax responds with the first data only..please help..
This question has an accepted answers - jump to answer
Answers
Because the Ajax operation it triggers is asynchronous. You need to wait for the
submitComplete
event to happen before you can trigger the next submit.A better solution would be to use multi-row editing so you can submit all changes in a single Ajax request.
Allan
Thank you as always!