dataTable fnUpdate row with new value

2020-02-10 04:07发布

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

5条回答
相关推荐>>
2楼-- · 2020-02-10 04:36

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.

查看更多
放我归山
3楼-- · 2020-02-10 04:38

Try:

$('#datatable').dataTable().fnUpdate(result, $('[data-id=' + idvalue + ']'), 8 );

This is best way to update column value without error and add table row with data-id="row id value" ....it works fine.

查看更多
爷的心禁止访问
4楼-- · 2020-02-10 04:39

You don't need to specify the column. Your issue is that you are using row ID when the doc states that 2nd argument can be the aoData index or the element.

Make sure your number of columns is correct, but you should be able to do it like so:

 $('#example').dataTable().fnUpdate( ['Zebra'], $('#example tr#3692')[0]);
查看更多
男人必须洒脱
5楼-- · 2020-02-10 04:42

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.

查看更多
别忘想泡老子
6楼-- · 2020-02-10 04:42

This works for me

var tableRow = $(this).closest('tr').index(); // GET TABLE ROW NUMBER
$('#table').dataTable().fnUpdate('Zebra', [tableRow], 1, false)
查看更多
登录 后发表回答