Test datatable exists

Test datatable exists

neburtonneburton Posts: 63Questions: 6Answers: 0
edited October 2010 in General
Is there any easy way to test if a datatable has been created?

I have a script that reloads several tables, but it stops if a reload is called on a table that hasn't been created yet.

table1.fnReloadAjax();
table2.fnReloadAjax();
table3.fnReloadAjax(); <--- If this doesn't exist, script stops here
table4.fnReloadAjax();

I've tried testing length, but that always returns 1?

Replies

  • neburtonneburton Posts: 63Questions: 6Answers: 0
    Just realised my question wasn't quite right.

    All datatables have been created, but the Ajax Source is set to null and loaded later. Some tables are loaded with data and others not. I need to test the table to see if it has been loaded with data?
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    There are a couple of ways. One way is to check what the sAjaxSource parameter is set to perhaps:

    table1.fnSettings().sAjaxSource

    Or you could see if there is any data in the table:

    table1.fnSettings().aoData.length (would fall over if there is truly no data to be display perhaps?)

    Or similar to the aoData length, you can use the DOM:

    $('#table_id tbody tr').length

    Allan
  • neburtonneburton Posts: 63Questions: 6Answers: 0
    Thanks for this, I will give it a go.
This discussion has been closed.