views:

264

answers:

1

I'm using JQuery Datatables and i'm wondering, for efficiency sake, if I should initialize the Datatable when the page loads. Then when the user submits their query, call the datatable API to addData?

Alternatively i could just initialize the DataTable with the server query string.

A: 

If there is a chance that the table will not be used on the page then initializing it on page load will be a waste and might slow down the page load.

However, if the initialization takes a significant amount of time and you don't want the user to wait for it to display the data, you could start initializing as soon as the user's query is submitted. This will take advantage of the time you will be spending waiting for a reply from the server. You might need a flag to show if the table is finished initializing once you're ready to display the returned data.

Donal Boyle