[英]How to redraw Datatable after selecting another page in JQuery Datatable?
我有一个DataTable,我从服务器端填充了数据。 表格已正确填充。 当我使用分页时,服务器端会再次调用并为下一页生成JSON数据。 数据正确。 但是桌子并没有刷新。 根据数据表文档,我知道我应该以某种方式使用draw()
函数,但是我不知道在哪里调用它。
这是我的html表:
<table id="table-esemenyLista" class="table table-striped table-bordered table-hover"> <thead> <tr> <th>Id</th> <th>Dátum</th> <th>Esemény</th> </tr> </thead> <tbody id="esemenyListBody" class="text-primary"> </tbody> </table>
这是与其连接的Jquery-datatable代码:
$( document ).ready(function() { esemenyListaTable = $("#table-esemenyLista").DataTable({ "processing" : true, "serverSide" : true, "paging" : true, "searching" : false, "lengthChange" : false, "drawCallback": function( settings ) { console.log('redrawn'); }, "ajax" : contextPath + "/historyContent.do" }); });
这是我第一次从server-sid获得的JSON对象(显示为正确):
{ "draw":1, "recordsTotal":16, "recordsFiltered":16, "data":[ [ 1, "2016-07-23", "text1" ], [ 12, "2016-10-04", "text2" ], [ 13, "2016-10-04", "text3" ], [ 16, "2016-10-18", "text4" ], [ 17, "2016-11-05", "text5" ], [ 18, "2016-11-14", "text6" ], [ 19, "2016-11-15", "text7" ], [ 20, "2016-11-16", "text8" ], [ 22, "2016-11-16", "text9" ], [ 23, "2016-11-17", "text10" ] ] }
转到第二页后,我得到以下JSON对象,该语法正确,但没有出现:
{ "draw":1, "recordsTotal":16, "recordsFiltered":16, "data":[ [ 24, "2016-11-17", "text11" ], [ 25, "2016-11-23", "text12" ], [ 26, "2016-11-23", "text13" ], [ 27, "2016-11-23", "text16" ], [ 28, "2016-11-24", "text17" ], [ 29, "2016-11-25", "text18" ] ] }
drawCallBack
函数仅在第一次写入日志。 我应该如何调用draw方法? 在我在StackOverflow上再次提出与我的问题相关的其他问题之后,我知道我应该清除然后重新绘制表,但是如何? 有人可以帮我吗?
您必须返回正确的draw
索引。 因此,第二个必须是“绘制”:2。 我不知道您的服务器端语言,在PHP中,您可以使用$_GET['draw']
获取绘制索引
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.