How to know if DataTable is ready?
How to know if DataTable is ready?
![Warbountho](https://secure.gravatar.com/avatar/9d0032c541b0cb02bbd6d19d1da567dc/?default=https%3A%2F%2Fvanillicon.com%2F9d0032c541b0cb02bbd6d19d1da567dc_200.png&rating=g&size=120)
Hi,
I test my app with Cypress, i often struggle to write tests with DataTables because it's hard to know when the instance is fully loaded.
How, with HTML only may i know if my instance is ready? Is a class added? Or will it be possible to add a class to the DataTable container when the instance is ready? I cannot rely on events.
Thanks!
Answers
initComplete
andinit
execute when the Datatables initialization is complete. You could add a class or whatever you need to do in one of those events to perform the actions needed when Datatables is ready.Kevin
In fact i tried with initComplete but it's not working... maybe because my table use ajax? I will look for ajax events.
OK i just figured out that if you search something that matches all rows, you don't have the placeholder 'Filtered from...' and i was relying on this.![:/ :/](https://datatables.net/forums/resources/emoji/confused.png)
What did you try and what exactly is not working?
I think you will find the
xhr
event executes beforeinitComplete
so the table initialization, ie populating the rows, has not completed whenxhr
fires. See this example:https://live.datatables.net/ralujoqo/1/edit
Maybe update the test case to show what is not working for you.
Kevin
Thanks for you help, in fact i was looking at the wrong place,
i assumed that "filtered from" text was always shown even if search matches all rows but it's not the case.
Don't this text should be always shown when a filter is applied?
Yes but unless you are using
search
orsearchCols
there won't be any initial filtering.What are you doing that would cause the table to be initially filtered?
Maybe you can post some code showing what you are doing.
Kevin
You mentioned adding a class. How about something like this:
https://live.datatables.net/ralujoqo/2/edit
Kevin