API and DOM initialise
API and DOM initialise
Hi
I am running Datatables and I have managed to find a way to run API to change "no. of Entries" shown, and also I am using DOM to replace in which order the elements are shown around the table.
I run these codes individually and they work, however, when I use them both, I get the - Cannot reinitialise DataTable error.
API code:
** var table = $('#datatable').DataTable();
table.page.len( 50 ).draw();**
DOM code:
**$('#datatable').dataTable( {
"dom": 'tip'
} );
**
Error:
"DataTables warning: table id=datatable - Cannot reinitialise DataTable. For more information about this error, please see http://datatables.net/tn/3"
From the message, I understand that I can only initialise the tables once, but I am not sure how to write this in a code?
Any help would be appreciated.
Thanks
Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
This question has an accepted answers - jump to answer
Answers
Are you executing this code:
Before this code?
If so the first one is initializing the Datatable with default options. The second one has init options so Datatables wants to initialize itself but that has already happened, That is why the error occurs.
You could swap the two code snippets and it would work.
Better would be to use the
pageLength
option and do this:Kevin
I tried this and the initialise error is not showing any more, but there is no effect on page length, still remains at default 10, but the "dom" does work.
Correction
After multiple page refreshes, it does work.
Thank you Kevin!