fnDestroy all Data Tables on page??

fnDestroy all Data Tables on page??

JimKnollJimKnoll Posts: 10Questions: 3Answers: 0

// This works for me
function unDataTableize() {
$("#DataTables_Table_0").dataTable().fnDestroy();
...
}

// I wanted to do it like below so I could convert the 0 into i using a for (var i = 0; i < tbls.length; i++)
// but I can not even get it to work for the first table index 0
function unDataTableize() {
var tbls = $('Table');
tbls[0].dataTable().fnDestroy();
}

//Can anyone point me to my mistake?

Answers

  • allanallan Posts: 61,928Questions: 1Answers: 10,153 Site admin

    tbls[0] gives you the DOM node, not a jQuery object, so there is no dataTable() method.

    In 1.10 you could simply use $('table.dataTable').DataTable().destroy(); with no need for any loops.

    Allan

  • JimKnollJimKnoll Posts: 10Questions: 3Answers: 0

    perfect thanks

  • JimKnollJimKnoll Posts: 10Questions: 3Answers: 0

    wait did you mean
    $('table.dataTable').dataTable().fnDestroy();
    not see cap
    $('table.dataTable').DataTable().destroy();

    While that works... it only seems to work on the first table defined on the page. not on subsequent tables.

  • JimKnollJimKnoll Posts: 10Questions: 3Answers: 0

    I am at 1.9.1 so I think I am good with that.

  • JimKnollJimKnoll Posts: 10Questions: 3Answers: 0

    function unDataTableize() {
    var tbls = $('table.dataTable');
    for (var i = 0; i < tbls.length; i++) {
    tbls.eq(i).dataTable().fnDestroy();
    }
    }

  • allanallan Posts: 61,928Questions: 1Answers: 10,153 Site admin

    wait did you mean [...]

    Nope - meant what I typed :-). Here is an example showing it working: http://live.datatables.net/sabesuju/1/edit .

    I am at 1.9.1 so I think I am good with that.

    Okay - the new API will not work. As I noted, in my comment above the code I suggested was for 1.10.

    Allan

This discussion has been closed.