【发布时间】:2016-10-06 14:48:04
【问题描述】:
我正在使用 jQuery DataTable 插件,但我有一个问题,在我的页面中我可以编辑来自特定行的信息我使用 AJAX 和 JavaScript 执行此操作,我的功能是这样的:
$.ajax ... code
success function... code and finally
DrawMyTable();
DrawMyTable 是另一个 AJAX,代码是这样的:
$.ajax ... code (Select * from and that stuff)
var html = "";
var html += "<tr>";
var html += "<td>";
var html += ... Then I do this for all the result from the Select Query;
var html += "</td>";
var html += "</tr>"; and finally
$('#MyTable').html(html);
$('#MyTable').DataTable().destroy(); //Looking here for answer I find that this could be a solution because before facing this issue I had the "cannot reinitialise datatable" error.
$('#MyTable').DataTable();
编辑#2
$('#MyTable').DataTable().destroy();
This have an error, the correct function is $('#MyTable').dataTable().destroy();
However with this I get the same issue, the table now is uptated but shows all the records.
编辑:
我尝试使用这个(通过这个更新表格,但显示我的所有记录,而不是仅显示 10、25 或用户选择的任何内容):
$("#MyTable").DataTable().fnDestroy();
$("#MyTable").DataTable();
这个:
$('#MyTable').DataTable({
bRetrieve: true
Or
$('#MyTable').DataTable({
destroy: true
但是我得到了相同的结果,我的表格按预期加载,但是当我编辑某些内容(编辑某些内容应该重新加载表格)出现我的成功按钮但我的表格在我重新加载页面之前不会改变,而且我的重新启动表分页(例如,一开始我每页显示 10 条记录,但是当我调用我的编辑函数时,表显示所有记录)我做错了什么?如何解决这个问题?
PD。我不能对 DataTable 使用 AJAX 选项,因为我需要插入我没有从 ajax 调用中获得的其他信息。
编辑#3
PD2。我的webservice很简单,就是一些sql查询。
【问题讨论】:
标签: javascript jquery datatable