我们已经和Datatables合作了一段时间,但是最近我们遇到了这个问题,在做了一些由模糊事件触发的计算之后,该事件应该影响我们表的几行中的值,一些值根本就不显示立即在屏幕上,需要在页面上显示另一个模糊(或者可能还在等待另一次重绘?)。
在线研究之后,我们决定测试fnUpdate功能。问题是,这似乎不适用于模糊处理程序。示例代码如下:
$('#myHtmlTable').on('blur', 'tbody td:nth-child(3)', function (e) {
var table = $('#myDatatable').DataTable();
//Iterate through the rows
table.rows().every( function ( index, tableLoop, rowLoop ) {
//gets the current row to work with
var row = table.row(index);
//do some calculations and come up with our values
// ...
//end of calculations
//we tried it like this, didn't work
row.field1 = value1;
row.field2 = value2;
row.field3 = value3;
//alternatively we used fnUpdate like this to no effect
//this throws an error that reads: "Failed to execute 'removeChild' on 'Node': The node to be removed is no longer a child of this node. Perhaps it was moved in a 'blur' event handler?"
$('#itensProdutoPrecoTable').dataTable().fnUpdate([value1, value2, value3], row.index())
});
});
看起来桌子实际上是IS更新的,我们的问题在于渲染值。 draw()调用也什么都不做。