ready() API documentation suggestion
ready() API documentation suggestion
kthorngren
Posts: 21,571Questions: 26Answers: 4,996
in Web-site
I was providing an example of using ready()
with multiple tables. The docs have this comment:
Scope is set to an API instance for the DataTable in question.
It took me a bit to figure out what this meant and how to get the API instance - I'm a bit slow The suggestion is to provide an example using multiple tables. For example:
let tables = new DataTable('.display');
tables.ready(function () {
// Get the API instance
let table = $( this ).DataTable();
// Actions to take when the table is ready
// ...
});
Kevin
Replies
Hi Kevin,
Good point - that requires some clarity and an example! However, it actually goes further than what your example has -
this
is already the API instance - e.g. the following would be equivalent to your example:No need to create a new API instance, the scope (
this
) already is the API instance.Allan
I tried that and it doesn't work. These errors appear depending on the form used:
Test case:
https://live.datatables.net/socirone/36/edit
Kevin
It looks like
this
is thetable
element not the API:https://live.datatables.net/gixezuwa/1/edit
See the console output.
Kevin
Oooo - I think you might have a bug there. I need to dash off atm (trees to chop down on a cold Scottish morning...), but I'll take a look when I get back.
Allan
Yup, most certainly a bug. The context of the callback was incorrect if the table wasn't yet "ready" (it was correct if it was already "ready").
I've committed a fix with a couple of unit tests.
Thanks for flagging this up and the excellent example as always!
Allan
Good thanks!
Kevin