Datatable with Scroller not working

2019-09-09 03:34发布

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条回答
时光不老,我们不散
2楼-- · 2019-09-09 03:45

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 ...

查看更多
登录 后发表回答