Multiple tables with same data source
Multiple tables with same data source
I am creating a website with 8 datatables using a class. All tables are using the same data source. But each table has its own search/filter applied to display a subset of the the data source.
The datasource is loaded with an Ajax call and reloaded every 20 seconds.
I am noticing that the datasource, and therfore the api and its database, are being called very often. I was asuming it would be 1 Ajax call every 20 seconds. Or is it multiplied by 8?
If it is 8, than what would be a better solution? I do not want to make to many calls to the api/database.
A working example can be found here.
live.datatables.net/diragezu/1/edit
Answers
A couple questions since I'm not seeing it in your example:
I assume you are doing something like
$('.example').DataTable().ajax.reload()
. IF so then yes I would expect 8 ajax requests. Each Datatable is independent even if the data source is the same.You could use
tables()
to control which tables send the relaod request to stagger them.The only other option I can think of is to remove the Datatables ajax option and use an external ajax request to generate one request. Doing this though you will lose the server side processing capability and you would have to work out a way to determine which response data goes to which table. You would use
clear()
androws.add()
to update each table. Might be complex depending on your filtering requirements.However if you are using server side processing I wouldn't think 8 requests would be too bad.
Others may have better ideas.
Kevin
Yes, that's excactly what I am using. $('.example').DataTable().ajax.reload()
I will look into the tables() api. Thank you.