DataTable re-initialization not working

DataTable re-initialization not working

rsalunga29rsalunga29 Posts: 6Questions: 2Answers: 0

Hello I've been trying the following methods but none is working.

Method 1:
$('#table').DataTable({
retrieve: true,
destroy: true
})

Method 2:
if($.fn.dataTable.isDataTable('#table')) {
$('#table').DataTable().destroy()
$('#table').DataTable({retrieve:true})
} else {
$('#table').DataTable({retrieve:true})
}

Method 3:
$('#table').DataTable().destroy()
$('#table').DataTable({retrieve:true})

Please help, thank you!

Answers

  • kthorngrenkthorngren Posts: 21,302Questions: 26Answers: 4,947

    Please describe what is not working. Do you get errors (alerts or browser's console)?

    Is the above the only Javascript code you have for initializing Datatables?

    Maybe you can post a link to your page or a test case showing the issue. This will give us the information needed to help you debug.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @rsalunga29 ,

    I'm not clear what you're doing there. The retrieve should be used when you want to access an already initialised table. You're using that

    1. when also requesting the table be destroyed
    2. after destroying the table if it exists, or when the table hasn't been initialised
    3. same as the first conditional in 2.

    So, I wouldn't expect that to work.

    Cheers,

    Colin

This discussion has been closed.