簡體   English   中英

如何在jQuery中將數據追加到數據表?

[英]How to append data to datatables in jquery?

我一直試圖將數據追加到jquery中的數據表,數據追加到數據表,但是數據表不能正常工作,這意味着排序,分頁,搜索不起作用。 數據表中甚至有數據,但顯示0條記錄。 我正在嘗試使所有功能正常工作,請為此提供幫助。

<table id="newexample1">
    <thead>
        <tr>
            <th>Name</th>
            <th>Employee</th>
            <th>InTime</th>
        </tr>
    </thead>
    <tbody class="tablebody">
    </tbody>
</table>
<script>
    function newfunction() {
        $(".tablebody").append("<tr onclick='historyfunction()'><td>Sasi Kumar</td><td>Suresh Kumar</td><td>21/06/2019 10:59:02</td></tr>");
    }
</script>
<script>
    $(document).ready(function() {
        $('#newexample1').DataTable();
    });
</script>

我期待一個正確的數據表。

function newfunction() {
        $(".tablebody").append("<tr onclick='historyfunction()'><td>Sasi Kumar</td><td>Suresh Kumar</td><td>21/06/2019 10:59:02</td></tr>");
        $(".tablebody").append("<tr onclick='historyfunction()'><td>omar omar</td><td>Suresh Kumar</td><td>21/06/2019 10:59:02</td></tr>");
    }

    $(document).ready(function() {
        newfunction();
        $('#newexample1').DataTable();
    });

是一個工作的JSfiddle

在您的代碼中,從不調用newfunction()因此當Datatable嘗試呈現表時,該表為空。 $(document).ready(function()實例化渲染數據表之前添加行(否則您將獲得0行表)。否則,如果要在渲染數據表后添加行,請使用rows.add()然后重繪該表在屏幕上使用draw()函數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM