jQuery:数据表查询
我正在使用 jQuery Datatable 插件将表渲染为 jQuery DataTable。我没有使用任何服务器端调用来获取表行详细信息。
我正在使用 jQuery 根据用户当前正在查看的页面上的可用信息生成表 HTML。
<头部> <正文>
当用户单击链接时,我使用 jQuery 构建表所需的行并将其设置到表主体。
之后,我初始化 dataTable,如下所示:
$('#list_table').dataTable({ “b处理”:假, “bJQueryUI”:正确, “bPaginate”:正确,
“bAutoWidth”:假, “b过滤器”:真, “bDestory”:正确,
"oLanguage": { "sZeroRecords": "无可用数据", "sSearch" :"过滤器" } 。
当用户第一次点击链接时,上面的代码工作正常 但是,如果用户再次单击,我收到错误 dataTable 会给出错误:
DataTables warning (table id = 'list_table'): Cannot reinitialise DataTable。 .....
即使显示了表格,它也会丢失其 Datatable CSS,搜索不再起作用,下一个上一个不再起作用。
我尝试了各种选项,例如设置 "bRetrieve" : true
还尝试检查数据表对象是否可用:
if (typeof dTable == 'undefined') {
dTable = $('#list_table').dataTable({
"bProcessing": false,
"bJQueryUI": true,
"bPaginate": true,
"bAutoWidth": false,
"bFilter" : true,
"bDestory" : true,
"oLanguage": { "sZeroRecords": "No data available", "sSearch" :"Filter" }
});
} else {
dTable.fnClearTable();
}
但似乎没有任何效果。我已将 DataTable 与服务器端 ajax 调用一起使用,以从工作正常的服务器重新加载数据,但在这种情况下,我不确定如何解决此问题。
谢谢。 杰伊
I am using jQuery Datatable plugin for rendering a table as jQuery DataTable. I am not using any server side calls for fetching table row details.
I am generating the table HTML using jQuery from the information available on the page the user is currently viewing.
<table cellpadding="0" cellspacing="0" border="0" class="display" id="list_table">
<thead>
</thead>
<tbody>
</tbody>
</table>
When a user clicks on a link, using jQuery I build the required rows for the table and set it to the table body.
After that I initialize dataTable as show below:
$('#list_table').dataTable({
"bProcessing": false,
"bJQueryUI": true,
"bPaginate": true,
"bAutoWidth": false,
"bFilter" : true,
"bDestory" : true,
"oLanguage": { "sZeroRecords": "No data available", "sSearch" :"Filter" }
});
The above works fine when the user clicks on the link for the first time. But if the user clicks again, the I get error dataTable gives error:
DataTables warning (table id = 'list_table'): Cannot reinitialise DataTable. .....
Even though the table is shown, it loses its Datatable CSS, search no longer works, next previous no longer works.
I have tried various options like setting "bRetrieve" : true
also tried checking if the datatable object is available:
if (typeof dTable == 'undefined') {
dTable = $('#list_table').dataTable({
"bProcessing": false,
"bJQueryUI": true,
"bPaginate": true,
"bAutoWidth": false,
"bFilter" : true,
"bDestory" : true,
"oLanguage": { "sZeroRecords": "No data available", "sSearch" :"Filter" }
});
} else {
dTable.fnClearTable();
}
But nothing seems to work. I have used DataTable with server side ajax call to reload data from the server where it works fine, but in this case I am not sure how to resolve this issue.
Thanks.
Jay
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果dataTable已经初始化,则无法再次初始化,因此如果
dataTable
不为null,您可以尝试像这样销毁dataTable
:然后您可以解决问题。
if the dataTable has been initialised, it can't be initialised again, so if the
dataTable
is not null, you can try and destroy thedataTable
like this:then you can solve the problem.
您将在数据表论坛上得到更好的答复...因为在这里我们分享了一些对所有人都有用的常见问题。
这是该论坛的链接..
DataTable 论坛
you will get better response of your question on dataTable forum...beacause here we shared some common problems which is use full to all people.
here is the link for that forum..
DataTable forum
解决此问题的一个快速简单的方法是将初始表放入 div 中,并在该 div 上运行empty().append(),然后再次构建表。我以为 bDestroy 参数会解决 css 和列标题问题,但事实并非如此。希望这对某人有帮助!
A quick and easy fix for this problem is to put your initial table inside a div and run an empty().append() on that div before building the table again. I thought the bDestroy parameter would take care of the css and column header problems but it did not. Hope this helps someone!