使用AJAX更新分页后,DataTables jQuery插件消失 [英] DataTables jquery addon dissapears after partialpage is updated with AJAX
问题描述
我有一个表,我想与 DataTables 插件一起使用.实际上,它的工作原理非常好,我可以按原样使用所有功能.
I have a table, which I want to use along with the DataTables plugin. Actually, it works really good, and I can use all the functionality as is.
不幸的是,我的表驻留在partialview中,因为当我在表中执行诸如删除和编辑之类的基本操作时,我认为利用AJAX来更新partial viewm非常好.
Unfortunately, my table reside in a partialview, because I thought it was neat to utilize AJAX to update the partial viewm when I do basic operations in my table such as Delete and edit.
我第一次使用部分视图加载页面时,DataTables可以正常工作.但是,如果删除或编辑实体,导致AJAX更新局部视图,则该功能将消失.
The first time I load my page with the partial view, DataTables attach and works. However, if I delete or edit my entities, causing AJAX to update the partial view, the functionality dissapears.
尽管我可以解决此问题,方法是将DataTables()
函数附加到包装局部视图的静态" div上,然后找到表类,如下所示:
I though that I could solve this, by attaching the DataTables()
function to the "static" div that wraps my partial view, and then find the table class, like so:
$(document).ready(function () {
$( "#partialViewWrapper" ).find( ".table" ).DataTable({
paging: false,
info: false
});
});
不幸的是,这不起作用.因此,我想知道如何以某种方式将DataTables附加到表上,以使更新局部视图不会分离"插件.
Unfortunately this does not work. Therefore, I would like to know, how I can attach DataTables to my table, in a way so that updating my partial view will not "detach" the plugin.
推荐答案
您需要在删除/编辑后刷新数据表.您可以根据需要使用加载/重新加载/绘制.
You need to refresh your datatable after delete/edit. you can use load/reload/draw as per your requirement.
1.如果您的ajax数据URL相同.然后尝试
1.If your ajax data url are same. Then try
yourDataTable.draw();
OR
yourDataTable.ajax.reload();
-
如果需要更新Ajax数据URL.然后尝试
If your need to update ajax data url. Then try
yourDataTable.ajax.url(newUrl).draw();
OR
var myParams = yourDataTable.ajax.params();
yourDataTable.ajax.url(newUrl, myParams).load();//if no parameter then pass null
这篇关于使用AJAX更新分页后,DataTables jQuery插件消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!