Check if DOM table is DataTable instance

Check if DOM table is DataTable instance

ZiTouNZiTouN Posts: 6Questions: 0Answers: 0
edited December 2011 in General
Hi,

Is there a way to determine if a "" is an instance of DataTable ?
Please consider the code below, where the "a.delete_button" is inside a part of a simple table, or a dataTable:

[code]
("a.delete_button").click(function() {

var $tr = $(this).closest('tr');
var $table = $(this).closest('tr').parents('table');

//Execute the fnDeleteRow() only if $table is a dataTable
$table.dataTable().fnDeleteRow($tr);

});
[/code]

Thanks.

Olivier

Replies

  • allanallan Posts: 61,723Questions: 1Answers: 10,108 Site admin
    edited December 2011
    Currently - no there isn't a built in way of checking this. There are "tricks" such as if ( $('#table_id').parents('dataTable_wrapper').length >= 1 ) which would work well, but a "True" method of doing it would be to loop over the DataTables settings object ($.fn.dataTableSettings) and look for the nTable property in each object. If the node is in there, then its a DataTable.

    Allan
  • ZiTouNZiTouN Posts: 6Questions: 0Answers: 0
    Dom parsing will be easy and effective as you suggest.

    Thank you for your quick answer Allan.
  • allanallan Posts: 61,723Questions: 1Answers: 10,108 Site admin
    Just edited my comment - it should be >= 1, rather than > 1!

    Allan
  • ZiTouNZiTouN Posts: 6Questions: 0Answers: 0
    I just put > 0 instead ;)

    Thanks !
This discussion has been closed.