简体   繁体   English

在JQuery Datatable中选择另一个页面后如何重绘Datatable?

[英]How to redraw Datatable after selecting another page in JQuery Datatable?

I have a DataTable which I fill with data from the server side. 我有一个DataTable,我从服务器端填充了数据。 The table is being filled the right way. 表格已正确填充。 When I use pagination, the server side is called again and produces the JSON data for the next page. 当我使用分页时,服务器端会再次调用并为下一页生成JSON数据。 The data is right. 数据正确。 But the table isn't refreshing. 但是桌子并没有刷新。 According to the Datatables documentation I know that I should use the draw() function somehow, but I don't know where to call it. 根据数据表文档,我知道我应该以某种方式使用draw()函数,但是我不知道在哪里调用它。

This is my html table: 这是我的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>

This is the Jquery-datatable code connected to it: 这是与其连接的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" }); });

This is the JSON object I get from the server-sid for the first time (appears right): 这是我第一次从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" ] ] }

After turning to the second page, I get the following JSON object, which is which syntax is right, but doesn't appear: 转到第二页后,我得到以下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" ] ] }

The drawCallBack function only writes the log the first time. drawCallBack函数仅在第一次写入日志。 How should I call the draw method? 我应该如何调用draw方法? After I red some other questions related to mine here on StackOverflow, I know I should clear, and then redraw the table, but how? 在我在StackOverflow上再次提出与我的问题相关的其他问题之后,我知道我应该清除然后重新绘制表,但是如何? Could someone help me please? 有人可以帮我吗?

You have to return the right draw index. 您必须返回正确的draw索引。 So the second one has to be "draw":2. 因此,第二个必须是“绘制”:2。 I don't know your serverside language, in PHP you can get the draw index with $_GET['draw'] 我不知道您的服务器端语言,在PHP中,您可以使用$_GET['draw']获取绘制索引

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM