I have several days trying to figure out how to set multiple rows programmatically.
The scenario is as follows:
I'm working with 2 tables
By selecting a row with the mouse in table nr.1 I get the row's Id, for further use. This is the piece of code:
// Get the selected Row Id and save it in solId to use below
var solId;
$('#levantamientos').on( 'click', 'tr', function () {
var rowId = table.row( this ).id();
var largo = rowId.length;
solId = rowId.slice(4,largo);
console.log( 'Solicitud: ' + solId );
} );
this works pretty good!
Then with a Button event, I go edit the table Nr2. and find out which rows have this index as reference, this, I do as follows:
var dtable= $("#mtto_correctivo_data").dataTable();
var nodes = dtable.fnGetNodes();
// Preprocesar string
var comString = "td:nth-child(2):contains(" + solId + ")";
var rowsSel = $(nodes).filter(function() {
return $(this).find(comString).length ;
});
rowsSel.css('background-color', 'yellow');
You can see that I mark the found rows with yellow background, this also works pretty good!
Then, of course I want to update a field named "status" with a new value!. Here I get a lot of problems, I have tried different methods. By end of the day, I'm trying following:
encontrados = rowsSel.length;
for (i=0; i< encontrados ; i++) {
console.log(rowsSel[i]);
var rowId = rowsSel[i].id;
var largo = rowId.length;
console.log(largo);
rowId = rowId.slice(4,largo); // Get the Id of the to change row
console.log('RowId: ' + rowId + ' Counter: ' + i);
editor.edit( table.row().index(rowId-1),
false
)
editor.set('estatus','COT') // Update status
editor.submit();
}
You can see a lot of console.log outputs for monitoring the process.
The point is, this part is working bad. It is working since it modifies some rows, but not the expected ones. sometimes, despite of that the output of console.log show everything is ok, it affect all rows!
For sure, I'm doing something wrong! but I don't know what!, please help me on this!
On the other side, I was reading in the manual, about a better and more elegant way to do this, something like this:
editor.field('reference.id').multiGet('id');
editor.field('status').multiSet('new_status');
I tried several times, but nothing happens! no errors are shown, no changes in the DOM and not in the Data Base!
What is the correct way to use these API's ?
Thanks in advance Allan!