dataTable fnUpdate row with new value

Viewed 51006

I am using datatables and have this tr element in table

<tr class="gradeA even row_selected" id="3692">
  <td class=" sorting_1">3692</td>
  <td class="">koza</td>
  <td class="" title="10:12:30">2013-12-31</td>
  <td class="">2014-02-06</td>
  <td class="">FULL packet</td>
  <td class="">NONE</td>
  <td class="">Name</td>
</tr>

I would like to update 1st and 4th td element using fnUpdate function. I have tried to update for only one td but it does not update.
In Chrome, console log I am getting this error:

Uncaught TypeError: Cannot set property '_aData' of undefined

Here is what I have tried:

 // dynamically update row
 $('#example').dataTable().fnUpdate( ['Zebra'], parseInt('3692'));

3692 is the id of the td element to know which row I need to update, and the zebra is the value to change. I know that I have not included which cell to update but I don't know how to do that. On datatables api, following example is given:

oTable.fnUpdate( ['a', 'b', 'c', 'd', 'e'], 1 ); // Row
6 Answers

This works for me

var tableRow = $(this).closest('tr').index(); // GET TABLE ROW NUMBER
$('#table').dataTable().fnUpdate('Zebra', [tableRow], 1, false)

In my case I wanted to update an entire row with data coming from backend as an object. Referring to:

$('#example').dataTable().fnUpdate('Zebra' , $('tr#3692')[0], 1);

I modified it a bit and used this lines of code to update an entire row without having to draw entire data table:

// get an selected row/row under edit action
let ele = $("#DTTableID")..dataTable().find('tr.row_selected');

$("#DTTableID").dataTable().fnUpdate(obj, ele);

Here obj is data object and ele is selected row.

Related