How to check when multiple table have loaded

How to check when multiple table have loaded

jdadwilsonjdadwilson Posts: 80Questions: 14Answers: 1

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

  • colincolin Posts: 15,143Questions: 1Answers: 2,586

    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

  • jdadwilsonjdadwilson Posts: 80Questions: 14Answers: 1

    Good idea, but... how do I know when all the tables have loaded? I activate the tables as follows...

    loadTableA();
    loadTableB();
    loadTableC();
    

    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?

  • colincolin Posts: 15,143Questions: 1Answers: 2,586

    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

  • jdadwilsonjdadwilson Posts: 80Questions: 14Answers: 1

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

    loadTableA();
    loadTableB();
    loadTableC();
    

    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

  • kthorngrenkthorngren Posts: 20,299Questions: 26Answers: 4,769

    You can use the $.fn.dataTable.isDataTable() API to determine if the table is a Datatable.

    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.

    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.

    Haven't really got my head around all the async stuff yet.

    Its not always easy to deal with the async operations :smile:

    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

This discussion has been closed.