0

我的数据表中有数据,我得到了这样的数据。现在我想在滚动时附加我的表格。这就像无限滚动。我想在我的数据表底部添加更多数据。有没有办法在我的场景中将新数据添加到现有数据表中?我正在尝试这种方式,但它不起作用。

HTML

    <table id="mytable" class="display dt-head-center">
        <thead>
            <tr>
                <th>First Name</th>
                <th>Last Name</th>
                <th>User Name</th>
                <th>Email</th>
                <th>Phone</th>
                <th>CreatedOn</th>
                <th>UpdatedOn</th>
            </tr>
        </thead>
        <tbody id="Userlist">            
        </tbody>
    </table>

jQuery代码

 $(document).ready(function () {
            UserRecords()
        });
        function UserRecords() {
            $.ajax({
                type: "Get",
                url: "/Manage/ShowAllResult",
                success: function (result) {
                    debugger;
                    console.log(result);                                     
                    $("#mytable").dataTable({
                        data: result,
                        "sDom": "Rlfrtip", //making Columns Resizeable and Reorderable
                        fixedHeader: true,
                        deferRender: true,
                        paging: false,
                        columns: [
                            { 'data': 'firstName' },
                            { 'data': 'lastName' },
                            { 'data': 'userName' },
                            { 'data': 'email' },
                            { 'data': 'phone' },
                            { 'data': 'createdOn', },
                            { 'data': 'updatedOn' },
                            ]
                   });  
}
});      

下一个 30 jQuery

function appenddata() {
            var table = $("#mytable").DataTable();
            $.ajax({
                type: "Get",
                url: "/Manage/ShowAllResult?count=" + table.rows().count(),
                success: function (appendresult) {
                    debugger;
                    var counter = appendresult.length;
                    console.log(appendresult);
                    finaldata = appendresult;
                    jQuery.each(finaldata, function (i, val) {
                        debugger;
                        table.row.add([
                            val.firstName,                            
                            val.lastName,
                            val.userName,
                            val.email,
                            val.phone,
                            val.createdOn,
                            val.updatedOn,                                                       
                        ]).draw();

                    });

                }

            });
        }
4

0 回答 0