数据表中的每一行都有一个删除按钮.
点击删除按钮,我调用此代码:
$('.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 –
fnReloadAjax()
子弹:
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
}
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。