Callback to use when multiple tables have finished loading

Callback to use when multiple tables have finished loading

tonykotonyko Posts: 13Questions: 7Answers: 0
edited April 2022 in Free community support

Hi, I'm using Datatables v1.10. I'm wondering if there is a callback I can use to figure out if 2 or more tables have finished loading.

Currently I use the initComplete callback, and once the table has finished loading, I hide the wait icon and show the page with the table.

I initialize 2 tables together, but I would like to configure them separately, and find a way to figure out when both tables have finished loading. So i can hide the wait icon and show both tables.

I've tried using init.dt...but to no avail

Thank you in advance.

Answers

  • kthorngrenkthorngren Posts: 21,344Questions: 26Answers: 4,954

    There isn't a callback that watches all Datatables for them to complete initialization. Maybe you can set a global flag for each Datatable in initComplete or init then see if the flag for all the Datatables has been set. If so then hide the wait icon.

    Kevin

  • tonykotonyko Posts: 13Questions: 7Answers: 0

    got it, so use something like setinterval, to check every 100ms whether both the variables have been set to true?

  • kthorngrenkthorngren Posts: 21,344Questions: 26Answers: 4,954

    I was thinking something like this:

    var table1Loaded = false;
    var table2Loaded = false;
    
        var table1 = $('#example').DataTable({
            initComplete: function () {
                table1Loaded = true;  //  table1 is loaded
    
                // Check to see if table2 is loaded
                if ( table2Loaded ) {
                    // Code to turn off wait icon
                }
            }
        });
    
        var table2 = $('#example').DataTable({
            initComplete: function () {
                table2Loaded = true;  //  table2 is loaded
    
                // Check to see if table1 is loaded
                if ( table1Loaded ) {
                    // Code to turn off wait icon
                }
            }
        });
    

    Will let you test this to make sure it works in with your solution.

    Kevin

  • tonykotonyko Posts: 13Questions: 7Answers: 0

    I can confirm that it works!
    Thank you sir, for the explanation and the example.

Sign In or Register to comment.