ajax 刷新 jquery datatable,ajax - Refresh jQuery datatable table - Stack Overflow

博客作者遇到一个问题,在使用jQuery和Ajax填充HTML表格后,无法成功更新带有DataTable插件的表格。他们尝试了.fnDraw(false)和.fnReloadAjax()等方法,但没有效果。问题在于如何在接收到新的JSON数据后正确刷新DataTable。
摘要由CSDN通过智能技术生成

Been plenty of questions about this but I never found one that worked for me. I have a plain and simple HTML table whos body is being filled with rows from an AJAX call.

Then I want to update the table with DataTable plugin but it does not work.

I have a HTML table that looks like this:

12345

In my jQuery pageload

$(document).ready(function(){

var oTable = $('#myTable').dataTable({

"aoColumns": [

{ "bSortable": false },

null, null, null, null

]

});

});

And finally my on dropdownlist change function

$("#dropdownlist").on("change", function () {

$("tbody").empty();

$.ajax({

type: "POST",

url: "@Url.Action("ActionHere", "Controller")",

dataType: "json",

success: function (data) {

$.each(data, function (key, item) {

$("tbody").append("

12345");

});

}

})

var oTable = $('#myTable').dataTable(); // Nothing happens

var oTable = $('#myTable').dataTable({ // Cannot initialize it again error

"aoColumns": [

{ "bSortable": false },

null, null, null, null

]

});

});

The append and so on has been modified to shorten it down, etc so do not focus too much on it.

Basically the question is how to update the table, I can do my AJAX and add new data to the table fine, but the datatable plugin does not update with it.

I've tried other things like

.fnDraw(false);

But it does nothing

While I get an JSON error from

fnReloadAjax()

Any clues on just how to refresh the table?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值