jquery - Is there a way to update the data in a row in dataTables? -


i using jquery , datatables display in table. works fine need able update specific row on button click. make clear attach screenshot:

enter image description here

i need when user pressing cancel button update values of row. right store values data attribute in <tr> element.
able them need find elegant way apply update.

does datatables provide functionality this?

edit

when create table, use createdrow event in order save values of specific element data attribute.

// add data using datatable lib var layer_data = $("#layer_data").datatable({   "scrollx": true,   "aadata":whole_array,   "idisplaylength": 10, // display 10 rows on each page   // on createdrow add data-initial attribute data of row   "createdrow": function ( row, data, index ) {     $.each($('td', row), function (colindex) {         $(this).parent().attr('data-initial', data);     });   } }); 

later use on click event (when cancel button clicked). retrieve values stored in data attribute. need put these values in cells of row.

// functionality cancel edits $(document.body).on("click", "._cancel_btn",function(e){   console.log($(this).closest('tr').attr('data-initial')); }); 

i think straight forward. have stored array of strings initial-data attribute on <tr>, these values should populated row columns :

$(document.body).on("click", "._cancel_btn",function(e) {   var row = $(this).closest('tr'),       data = row.attr('data-initial').split(',')    (var i=0; i<data.length; i++) {     table      .row(row)      .nodes()      .to$()      .find('td:nth-child('+ (i+1) +')') //css indexes 1-based      .text(data[i])   } }) 

the above works directly on datatables internal nodes. same in "pure" jquery , after invalidate() row :

for (var i=0; i<data.length; i++) {   $('td:nth-child('+(i+1)+')', row).text(data[i]) } layer_data.row(row).invalidate() 

btw createdrow improved. inserting data-initial n times (for each column) need

createdrow: function ( row, data, index ) {   $(row).attr('data-initial', data); } 

Comments