在我的 Jquery 数据表中,row.add
不工作并抛出一个错误,指出添加函数未定义。错误信息是:
Uncaught TypeError: Cannot read property 'add' of undefined
html
<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
</tr>
</tfoot>
</table>
<button id="addRow">Add new row</button>
javascript
$(document).ready(function() {
var counter = 1;
var prntTable = $('#example').dataTable( {
"aoColumns" : [
{"bSearchable" : false},
{"bSearchable" : true},
{"bSearchable" : true}
],
"sPaginationType" : "full_numbers"
} );
$('#addRow').on( 'click', function () {
prntTable.row.add( [
counter +'.1',
counter +'.2',
counter +'.3'
] ).draw();
counter++;
} );
$('#addRow').click();
} );
最佳答案
代替:
var prntTable = $("#example").dataTable();
尝试:
var prntTable = $("#example").DataTable();
看起来旧数据表 API dataTable()
不支持您正在调用的函数。使用新的 API:DataTable()
。阅读此处了解更多信息:Datatable API
关于javascript - 在 jquery 中向 dataTable 添加行的函数给出 TypeError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27119920/