jQuery Datatable排序问题

时间:2014-11-27 13:13:24

标签: javascript jquery datatable

我正在使用Datatable插件

http://www.datatables.net/examples/basic_init/zero_configuration.html

填充表我使用jquery .html()函数并将表内容传递给它。

问题是在将数据附加到表后,所有排序,分页和搜索功能都不再起作用,每次更改都会从表中删除数据。

有人可以帮我解决这个问题吗?

谢谢

1 个答案:

答案 0 :(得分:1)

您可以使用备用方法使用Datatable的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/