我正在使用数据表插件
http://www.datatables.net/examples/basic_init/zero_configuration.html
为了填充表格,我使用 jquery .html() 函数并将表格内容传递给它。
问题是在数据附加到表后,所有排序、分页和搜索功能都不再工作,每次更改都会从表中删除数据。
谁能帮我解决这个问题吗?
谢谢
最佳答案
您可以使用数据表的 row.add
功能使用替代方法将数据添加到表中。
代码如下:
JQuery
$(document).ready(function() {
var t = $('#example').DataTable();
$('#addRow').on( 'click', function () {
t.row.add( ['a','b','c','d','e'] ).draw();
} );
} );
HTML
<button id="addRow">Add</button>
<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
<th>Column 4</th>
<th>Column 5</th>
</tr>
</thead>
</table>
您可以在开始时隐藏表格的可见性,并在填充数据后显示表格。
JSFiddle:http://jsfiddle.net/ntgm9rde/1/
关于javascript - jQuery 数据表排序问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27171602/