I have a datatable showing all employees.
It is working fine for all employees on document.ready.
I have a select tag containing the type of employees like
This tech note section from datatables explains the reason for this warning. Relevant information from there:
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 } );
The above documentation explains two ways to deal with this.
table = $('#example').DataTable( { retrieve: true, paging: false } );
Destroy: In this case you can destroy the object explicitly by calling table.destroy(); and then creating the table again. Or you can simply pass destroy: true option as mentioned in the accepted answer.
table = $('#example').DataTable( { paging: false } ); table.destroy(); table = $('#example').DataTable( { searching: false } );
Using destroy:true option:
$('#example').DataTable( { destroy: true, searching: false } );
Note: This error may also occur if you include your javascript file that creates the dataTable multiple times. I was using apache tiles and included it in base as well as extended definition which also resulted in this error.