数据表中的每一行都有一个删除按钮.
$('.deleteButton').live('click',function () {
var $this = $(this);
var url = $this.attr("id");
$("#example").fnReloadAjax();
$.getJSON(url,Success());
});
url是控制器的动作,它接收Id并从数据库中删除数据.这样可行.
我现在想要调用datatable的刷新/重绘功能,以便它可以加载新的结果,但它不起作用.
数据表是:
$("#example").dataTable({
"aoColumns": [
{ "sTitle": "Id" },{ "sTitle": "Name" }],"bProcessing": true,"bServerSide": true,"sAjaxSource": '@Url.Action("FetchData","Home")',"sPaginationType": "full_numbers",});
有人可以请教吗?
最佳答案
引自API datatable page –
原文链接:https://www.f2er.com/jquery/428212.htmlfnReloadAjax()
子弹:
Note: To reload data when using server-side processing,just use the
built-in API function fnDraw rather than this plug-in.
因此,您最好使用fnDraw
.
[编辑]实际上,你的通话顺序应该是:
// you don't have to use $.json because you don't use the downloaded data
// first,ask the server to delete the data
$.ajax({
url: urlToDelete,success: function() {
// if it worked,ask datatable to redraw the table with the new data
$("#example").dataTable().fnDraw();
// if this js function does anything useful (like deleting the row),then call it:
Success();
},error: function() {
// display any error (like server couldn't be reached...),or at least try to log it
}
});