How to get dataTable object after init?

How to get dataTable object after init?

motmot Posts: 5Questions: 0Answers: 0
edited April 2010 in General
The suggested way to use dataTables is:
[code]oTable = $('#tDataTable').dataTable(...);[/code]
Then I can do whatever I want with oTable object.

But I want to work another way:
[code]$('#tDataTable').dataTable(...);//init
...
oTable = $('#tDataTable').dataTable();//wanted action - get dataTable object.
oTable.fnUpdate(...);
[/code]

How can I make it come true?:)

Replies

  • kapacitykapacity Posts: 2Questions: 0Answers: 0
    I use the JQuery .data() function to assign a data element to the table:

    ...

    //---
    $(".datatable").each(function () {
    var oTbl = $(this).dataTable();
    $(this).data('datatable', oTbl);
    });
    //---

    // Then you can retrieve it from the table element
    var oTbl = $("#myTable").data('datatable');
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    This is an old thread now - since 1.8 (possibly 1.7 - can't actually remember off the top of my head) you can do exactly as mot suggests - you don't need to use $().data - you can just call the $().dataTable function on your table again without any options being passed.

    Allan
This discussion has been closed.