Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dataTable fnUpdate row with new value

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
like image 488
user2631534 Avatar asked Dec 31 '13 19:12

user2631534


3 Answers

I prefer this:

var myDataTable= $('#myDataTableId').DataTable();
var row = myDataTable.row( '#idRow');
myDataTable.cell(row, 2).data("New Text").draw();

Note:

2 is column, cell inside modified row.

like image 131
Dani Avatar answered Nov 15 '22 14:11

Dani


This works for me

var tableRow = $(this).closest('tr').index(); // GET TABLE ROW NUMBER
$('#table').dataTable().fnUpdate('Zebra', [tableRow], 1, false)
like image 23
Goran Siriev Avatar answered Nov 15 '22 14:11

Goran Siriev


Please review the docs here http://datatables.net/api

Your question is not complete, as you need to specify what column(td) you want to modify, but here's what I would try (assuming you want to update the second column).

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

The second parameter will be the row, and the third is the column.

Note that I passed in a string.

like image 14
josephtikva1 Avatar answered Nov 15 '22 15:11

josephtikva1