How to check when multiple table have loaded
How to check when multiple table have loaded

This is somewhat of a basic question but being an old novice I'm not sure how to handle it.
My site has a search feature that allows the user to search multiple database tables with a single entry. The results of each ajax json query loads a datatable with the results. Using initComplete I set a unique flag (T/F) when an individual table has loaded and get the number of records loaded into the table. If the number of records is zero the table is hidden.
If all the queries return zero records I would like to inform the user rather than displaying a blank page. My 'problem' is how do I use the results of each table to then determine that all are finished.
An old type solution would be to start the first table load and then in the initComplete of the first start the second etc. This is how it would be handled in FORTRAN II but I think the world of 'programming' has advanced past that stage.
Any thoughts/help is most appreciated
jdadwilson
msgwcc@msholmes.org
Answers
Hi @jdadwilson ,
If all the tables are in the DOM, then you could check after you've hidden each table whether there are any unhidden tables - and if there isn't, then display your message. That should do the trick,
Cheers,
Colin
Good idea, but... how do I know when all the tables have loaded? I activate the tables as follows...
In the initComplete of each 'table' I check the number of rows created and then show the table if positive rows were generated. Where then do I check that ALL of the subject table are Hidden?
Hi @jdadwilson ,
If they start visible, and you're turning them invisible individually, you don't need to know if they've all been loaded, you care when they're all invisible.
Hope that makes sense,
Cheers,
Colin
All starting visible or invisible is not the issue. The issue is HOW in the code do I check the state. As indicated before each table build is in a function...
So, how do I check on the status. If I place a checkStatus function after the loads it will always return false given that the table loads all start but may not finish before the checkStatus is fired.
Thanks for your assistance. I really appreciate your help. There is probably something that I am missing in all of this. I know enough to be dangerous. I'm to old school. Haven't really got my head around all the async stuff yet. Understand that my profile picture was taken in 1964.
jdadwilson
You can use the
$.fn.dataTable.isDataTable()
API to determine if the table is a Datatable.I'm a bit confused as you mentioned checking status in
initComplete
and setting a flag. Does this not work for you? Maybe you can do what you want (hide/show the table or whatever) in the initComplete function for each Datatable.Its not always easy to deal with the async operations
Maybe you can provide more specifics of what you want to do in the checkStatus function. I suspect you can just do what you want in initComplete.
Kevin