DataTables has a wide range of configuration options which can be used to customise the table at initialisation time, but only at initialisation time. After a DataTable has been initialised any attempt to use these options will result in an error.
Meaning
Simply put, DataTables does not allow initialisation options to be altered at any time other than at initialisation time. Any manipulation of the table after initialisation must be done through the API and trying to set the initialisation options once the table has already been initialised will result in the error
This error is triggered by passing in options to a DataTables constructor object when the DataTable instance for the selected node has already been initialised. For example:
$('#example').dataTable( {
paging: false
} );
$('#example').dataTable( {
searching: false
} );
will result in an error when the second block of code is run, since #example is already initialised as a DataTable.
Resolution
There are a number of ways that this error can crop up in code, so there also a number of different methods that can be used to resolve the issue, depending upon exactly what you are trying to achieve.
Single initialisation
If you want to make use of multiple DataTables initialisation options, simply apply them all together to the table. In the case of the example error above, where we try to disable paging and searching we would use:
$('#example').dataTable( {
paging: false,
searching: false
} );
Object instance retrieval
if ( $.fn.dataTable.isDataTable( '#example' ) ) {
table = $('#example').DataTable();
}
else {
table = $('#example').DataTable( {
paging: false
} );
}
retrieve
table = $('#example').DataTable( {
retrieve: true,
paging: false
} );
destroy
table = $('#example').DataTable( {
paging: false
} );
table.destroy();
table = $('#example').DataTable( {
searching: false
} );
Hope that helps you out.