Creating new table through ajax and setting it to datatable
Creating new table through ajax and setting it to datatable
Hi,
first, your code is great! datatables is the best jquery plugin i never used.
I'm populating a page with tables, through ajax. I 'm looking to make that new tables "datatables", but my js says is imposible to re-initialize the datatables.
All my datatables have the same class ".datatable" so my call on load is:
[code]
jQuery('.datatable').dataTable();
[/code]
every time i add a table through jquery .load() method, i add to the callback that call: jQuery('.datatable').dataTable(); but here is when the error comes.
How can i set new tables as datatables after callbacks with .load()?
first, your code is great! datatables is the best jquery plugin i never used.
I'm populating a page with tables, through ajax. I 'm looking to make that new tables "datatables", but my js says is imposible to re-initialize the datatables.
All my datatables have the same class ".datatable" so my call on load is:
[code]
jQuery('.datatable').dataTable();
[/code]
every time i add a table through jquery .load() method, i add to the callback that call: jQuery('.datatable').dataTable(); but here is when the error comes.
How can i set new tables as datatables after callbacks with .load()?
This discussion has been closed.
Replies
any help would be appreciated.
However, the interaction can become complicated if you are using that selector on every initialisation. As the error says, you cannot re-initialise a DataTable (you can destroy it and then create it again if you want to do that). So for example:
[code]
jQuery('.datatable').dataTable();
// ... some code to create a table (and not remove the old ones) ...
jQuery('.datatable').dataTable();
[/code]
will not work. Perhaps you can provide a link to show us how you are doing the initialisation?
Allan
First, thank you for such a great product. I am doing the same thing as Surtido (using load() to populate a div with a new table). I reviewed how multiple tables are initialized in the example you link to above. My query is this. If one of those tables were loaded dynamically (i.e., after the page had loaded, using ajax), would it be initialized?
Best
Mike
It might be... The table will only be initialised if it is available in the DOM (i.e. if the selector $('.datatable') matches your table). If it doesn't then there is no way for DataTables to know that you are going to add a table to the DOM in future (there is no "live" support) so no action can be taken on it. You must have the table in the DOM to be able to initialise it.
Allan