Cancel ajax request on draw.dt
Cancel ajax request on draw.dt
I have 10 datatables on the page at once, but only one is active. The rest will be available when switching between tabs. Upon loading the main page, I initialize the tables through $('#...').DataTable(), which in turn launches 10 ajax requests to the server at once, which heavily loads it. Is it possible to initialize tables without sending ajax to the server on draw.dt event, and send a request only by click on a specific tab ? Or will I have to load the table only by click on the tab, and accordingly initialize it in the same place?
This question has an accepted answers - jump to answer
Answers
If you use the
ajaxoption then Datatables will fetch the data on initialization. There isn't an option to delay this. Unless you are using server side processing, ieserverSide: true, then you can usedeferLoadingto stop the initial request.Here are some options:
xhrevent of the first Datatable to initialize the second Datatable.ajaxoption. Then use jQuery ajax to fetch the data for the table of the tab being opened and in thesuccessfunction userows.add()to populate the Datatable.There are probably other ways you can do this depending on your environment.
Kevin
Thanks, Kevin! I chose the way to initialize the DataTable separately on each page.