如何在删除行后刷新jquery数据表

前端之家收集整理的这篇文章主要介绍了如何在删除行后刷新jquery数据表前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

数据表中的每一行都有一个删除按钮.

点击删除按钮,我调用代码

$('.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 pagefnReloadAjax()子弹:

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
   }
});
原文链接:https://www.f2er.com/jquery/428212.html

猜你在找的jQuery相关文章