How to check if a variable is an initialized DataTable?

How to check if a variable is an initialized DataTable?

dtdevdtdev Posts: 9Questions: 4Answers: 0
edited September 2016 in Free community support

It looks like $.fn.dataTable.isDataTable() works for selectors, but not for variables containing an initialized DataTable. I assumed this function could be used for this purpose, but it is returning false for such variables:

var table = $("#table").DataTable(); // Valid initialized DataTable
console.log($.fn.dataTable.isDataTable("#table")); // Returns true
console.log($.fn.dataTable.isDataTable(table)); // Returns false...why?

Why does this function return false? Is there a way to check variables to see if they are an initialized DataTable? How else can a variable be determined to be an initialized DataTable or not? I'm basically trying to do this:

// variable can be an initialized DataTable, string (selector), or jQuery object...
if (isDataTable(variable)) {
    // datatable ... do datatable stuff
} else {
    // not a datatable... do other stuff
}

Thanks!

This question has an accepted answers - jump to answer

Answers

This discussion has been closed.