jquery datatable update row cell value 1

jquery datatable update row cell value

let msg = { id: 1, customer_name: 'Fred' };  // source of updates (from backend)
let row = table.row('#row-' + msg.id);
let rowindex = row.index();                                                            
let columns = table.settings().init().columns;                                      
table.columns().every(function (colindex) {     
     let coldata = columns[colindex].data;  // 'data' as in the DT column definition
     if (coldata != 'id' && msg.hasOwnProperty(coldata)) {  // (don't update the id!)
         table.cell({row: rowindex, column: colindex}).data(msg[coldata])  
     }                                                                              
});

Here is what the above code is Doing:
1. Get the row index of the row to be updated.
2. Get the column definitions of the table.
3. Iterate through the columns.
4. For each column, if the column name is not ‘id’ and the message has a property with the same name, update the cell.

Similar Posts