使用Scroller的数据表不起作用 [英] Datatable with Scroller not working
问题描述
使用DataTable的最新版本(1.10.9)和滚动器小部件(1.3.0),我无法使它与以下简单代码段一起工作:
Using the last version of DataTable (1.10.9) and the scroller widget (1.3.0), I can't make it work with this simple piece of code:
var data = [{'a': 'a', 'b': 'b'}, {'a': 'c', 'b': 'd'}];
var columns = [{'title': 'a', 'data': 'a'}, {'title': 'b', 'data': 'b'}];
$("#mytable").DataTable({
"processing" : true,
"filter": false,
"orderClasses": false,
"ordering": false,
data: data,
deferRender: false,
scrollY: 400,
scrollCollapse: true,
scroller: {
loadingIndicator: true
},
dom: "rtiS",
columns: columns,
});
结果,我有一个空表,并显示消息显示NaN到-Infinity of 2个条目".在没有滚动器小部件的情况下,它工作正常(但我需要它).
As a result, I have an empty table with message "Showing NaN to -Infinity of 2 entries". WIthout the scroller widget, it is working fine (but I need it).
我想念什么?
推荐答案
我找到了原因=>我从ajax响应中应用了DataTable,该响应也将表插入到DOM中.
I found the reason => I apply DataTable from an ajax response that also insert the table into the DOM.
在$(document).ready中调用JS会导致该错误.
Calling the JS in a $(document).ready causes the bug.
使用setTimeout可以避免错误...
Using a setTimeout avoids the bug ...
这篇关于使用Scroller的数据表不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!