Determine if DataTables are running in version 1.10. Is there a callback?

How to determine if DataTables () is being rendered in version 1.10 and higher? Is there a callback somewhere where I can set the function. I would like to hide my table until the DataTables is finished and then open it after loading it.

With version 1.10, I did not encounter a callback, and I think that many old callbacks are now deprecated, as their links redirect me to legacy.datatables.net

+5
source share
1 answer

You can use the init.dt event as follows:

 $('#example').on('init.dt', function(e, settings, json){ console.log( 'Table initialisation complete: '+new Date().getTime() ); }); $('#example').dataTable(); 

From the manual:

init event is raised when your table is fully initialized, loaded, and rendered, especially when using an ajax data source.

NOTES

If you are going to hide / show the table, you will need to use the columns.adjust() method to recalculate the width of the columns after the table becomes visible.

For instance:

 $('#example-container').hide(); $('#example').on('init.dt', function(e, settings, json){ $('#example-container').show(); $(this).DataTable().columns.adjust(); }); $('#example').dataTable(); 
+4
source

All Articles