问题 dataTable fnUpdate具有新值的行


我正在使用数据表并且有这个 tr 元素 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>

我想更新第1和第4 td 元素使用 fnUpdate 功能。我试图只更新一个 td 但它没有更新。
在Chrome中,控制台日志我收到此错误:

未捕获的TypeError:无法设置未定义的属性'_aData'

这是我尝试过的:

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

3692 是的id td 要知道我需要更新哪一行的元素,以及 zebra 是要改变的价值。我知道我没有包括要更新的单元格,但我不知道该怎么做。在datatables api上,给出了以下示例:

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

2827
2017-12-31 19:41


起源



答案:


请在此处查看文档 http://datatables.net/api

您的问题不完整,因为您需要指定要修改的列(td),但这是我要尝试的(假设您要更新第二列)。

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

第二个参数是行,第三个是列。

请注意,我传入了一个字符串。


12
2017-12-31 19:55



plus 1 对于 second parameter will be the row, and the third is the column. - Kishor Pawar


答案:


请在此处查看文档 http://datatables.net/api

您的问题不完整,因为您需要指定要修改的列(td),但这是我要尝试的(假设您要更新第二列)。

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

第二个参数是行,第三个是列。

请注意,我传入了一个字符串。


12
2017-12-31 19:55



plus 1 对于 second parameter will be the row, and the third is the column. - Kishor Pawar


我更喜欢这个:

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

注意:

2是列,修改行内的单元格。


2
2018-04-11 20:47





您无需指定列。您的问题是,当doc声明第二个参数可以是aoData索引或元素时,您正在使用行ID。

确保您的列数正确,但您应该能够这样做:

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

0
2018-05-15 18:40





尝试:

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

这是更新列值而不出错的最佳方法,并添加表行 data-id="row id value" ....它工作正常。


-1
2017-07-02 10:28