成功调用ajax后数据表未更新

时间:2014-11-11 09:41:18

标签: javascript jquery ajax asp.net-mvc datatable

我正在从datatable中删除行,然后在删除记录后,我再次绑定表行,然后再次调用dataTable函数,但它没有更新底部显示的记录总数。 从服务器端我得到更新的记录数,并在我的表中更新了行数。但dataTable显示的总数未更新。 这是我的ajax代码

 $(document).delegate('.Delete', 'click', function () {
            var getDeleteID = parseInt($(this).closest('tr').find('td:eq(0)').find('span').text());

            BootstrapDialog.confirm('Are you sure you want to delete person?', function (result) {
                if (result) {
                    $.ajax({
                        type: 'GET',
                        contentType: 'application/json; charset=utf-8',
                        url: '/Home/DeleteData',
                        data: { Id: getDeleteID },
                        dataType: "json",
                        success: function (data) {
                            BindTable(data);

                        },
                        error: function (data) {
                            alert("Error In Deleting Person ");
                        }
                    });

                }
            });
        });
    });

这是我的BindTable功能

  function BindTable(data) {

        var tabHtml = '';
        $.each(data, function (i, d) {
            tabHtml += "<tr><td><span class='hide'>" + d.ID + "</span>" + d.Name + "</td><td>" + d.Position + "</td><td>" + d.Age + "</td><td>" + d.Salary + "</td><td><span class='Edit ML10'>Edit</span><span class='Delete ML10'>Delete</span> </tr>";
        });
        $('#dbTable').find('tbody').html(tabHtml);
        $('#dbTable').dataTable();
    }

HTML:

<table id="dbTable" class="table table-striped table-bordered" cellspacing="0" width="100%">
    <thead>
        <tr>
            <th>
                Name
            </th>
            <th>
                Position
            </th>
            <th>
                Age
            </th>
            <th>
                Salary
            </th>
            <th>
                Action
            </th>
        </tr>
    </thead>
    <tbody>
    </tbody>
</table>

0 个答案:

没有答案