问题
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,
});
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).
What did I miss?
回答1:
I found the reason => I apply DataTable from an ajax response that also insert the table into the DOM.
Calling the JS in a $(document).ready causes the bug.
Using a setTimeout avoids the bug ...
来源:https://stackoverflow.com/questions/32652947/datatable-with-scroller-not-working