0

firstly apologise as this may seen duplicate since I've searched another solutions before proceed this but still can't figure it out. I initialise the Datatables table inside this code:-

$('#get_contacts').on('show.bs.modal', function(e)
{
$('#contacts_table').DataTable({
 deferRender: true,
 responsive: true,
 'bPaginate': false,
 'bInfo': false,
 ajax: 'send_sms_lib.php?mode=listContacts',
 columns: [
 {data:'contact_id'},
 {data:'contact_name'},
 {data:'mobile_numb'},
 {data:'contact_id'}
 ],
 'columnDefs': [{
 'targets': 3,
 'searchable': false,
 'orderable': false,
 'render': function (data, type, row){
 return '<input type="checkbox" id="no" name="no" value="'+data+'">';
 }
 }]
 });
/* *comment temporary since I'm doing my own testing*
 $('#group_table').DataTable({
 deferRender: true,
 responsive: true,
 'bPaginate': false,
 'bInfo': false,
 ajax: 'send_sms_lib.php?mode=listGroup',
 columns: [
 {data:'group_id'},
 {data:'group_name'},
 {data:'contact_name'},
 {data:'group_id'}
 ],
 'columnDefs': [{
 'targets': 3,
 'searchable': false,
 'orderable': false,
 'render': function (data, type, row){
 return '<input type="checkbox" id="no" name="no" value="'+data+'">';
 }
 }]
 });
 $('#global_contacts_table').DataTable({
 deferRender: true,
 responsive: true,
 'bPaginate': false,
 'bInfo': false,
 ajax: 'send_sms_lib.php?mode=listGlobalContacts',
 columns: [
 {data:'contact_id'},
 {data:'contact_name'},
 {data:'mobile_numb'},
 {data:'department'},
 {data:'contact_id'}
 ],
 'columnDefs': [{
 'targets': 4,
 'searchable': false,
 'orderable': false,
 'render': function (data, type, row){
 return '<input type="checkbox" id="no" name="no" value="'+data+'">';
 }
 }]
 });
 $('#global_group_table').DataTable({
 deferRender: true,
 responsive: true,
 'bPaginate': false,
 'bInfo': false,
 ajax: 'send_sms_lib.php?mode=listGlobalGroup',
 columns: [
 {data:'group_id'},
 {data:'group_name'},
 {data:'contact_name'},
 {data:'department'},
 {data:'contact_id'}
 ],
 'columnDefs': [{
 'targets': 4,
 'searchable': false,
 'orderable': false,
 'render': function (data, type, row){
 return '<input type="checkbox" id="no" name="no" value="'+data+'">';
 }
 }]
 });*/
});

But when I launced the modal, it keeps pop-up the errors as here:-

DataTables warning: table id=contacts_table - Cannot reinitialise DataTable. For more information about this error, please see http://datatables.net/tn/3

I would like to destroy or if possible to say it as de-initialise the table since the modal consist of multiple menu tabs & intend to destroy table of another tabs to re-initialise table from selected. Here's the code where I intend to do the destroy process:-

$('#get_contacts').on('hidden.bs.modal', function () {
});
asked Dec 16, 2016 at 2:52

2 Answers 2

7

Try using .fnDestroy():

$('#get_contacts').on('hidden.bs.modal', function () {
 $('#contacts_table').dataTable().fnDestroy();
});
answered Dec 16, 2016 at 3:19
Sign up to request clarification or add additional context in comments.

4 Comments

it's working! thanks @Nishanth Matha. I've add the rest of datatables code as here:- $('#get_contacts').on('hidden.bs.modal', function () { $('#contacts_table').dataTable().fnDestroy(); $('#group_table').dataTable().fnDestroy(); $('#global_contacts_table').dataTable().fnDestroy(); $('#global_group_table').dataTable().fnDestroy(); });
just try, it's not working as your suggestions. my pleasure to have your check on my answers below to modify it if necessary, so I may test again. thanks! =)
I try this $('#get_contacts').on('hidden.bs.modal', function () { $('#contacts_table#group_table#global_contacts_table#glob‌​‌​al_group_table').d‌​a‌​taTable().fnDestr‌​oy(‌​); }); by removing tailing , but the table unload, just the header loaded. Is there somewhere I'm still missing?
still same, cannot work as per your suggestions. but nvm, I'll keep with my first comment & I'm highly appreciate your assistance & supports.
1

I've try the answers by @Nishanth Matha & add the rest of datatables code as here:-

$('#get_contacts').on('hidden.bs.modal', function () {
 $('#contacts_table').dataTable().fnDestroy();
 $('#group_table').dataTable().fnDestroy(); 
 $('#global_contacts_table').dataTable().fnDestroy(); 
 $('#global_group_table').dataTable().fnDestroy(); 
});

The result of it is the message as in questions not appears again.

answered Dec 16, 2016 at 3:29

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.