简体   繁体   English

jQuery Datatable排序问题

[英]jQuery Datatable sort issue

I am using the Datatable plugin 我正在使用Datatable插件

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

to populate the table I use jquery .html() function and pass the table content to it . 要填充表,我使用jquery .html()函数并将表内容传递给它。

the problem is after the data is appended to the table all the sort , paginate and search functions are not working anymore , each change on these removes the data from the table . 问题是将数据添加到表后,所有的排序,分页和搜索功能都不再起作用,对这些函数的每次更改都会从表中删除数据。

can anyone help me with this problem please ? 有人可以帮我解决这个问题吗?

thank you 谢谢

You can use an alternate method to add the data to the table using the row.add functionality of the Datatable. 您可以使用备用方法,通过Datatable的row.add功能将数据添加到表中。 Here's the code: 这是代码:

JQuery JQuery的

$(document).ready(function() {
    var t = $('#example').DataTable();

    $('#addRow').on( 'click', function () {
        t.row.add( ['a','b','c','d','e'] ).draw();
    } );
} );

HTML 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>

You can keep the visibility of the table hidden during the start and once the data is populated, show the table. 您可以在开始时将表的可见性保持隐藏状态,并在填充数据后显示表。

JSFiddle: http://jsfiddle.net/ntgm9rde/1/ JSFiddle: http : //jsfiddle.net/ntgm9rde/1/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM