Using oTable.fnOpen inside fnDrawCallback

Using oTable.fnOpen inside fnDrawCallback

andreydruzandreydruz Posts: 2Questions: 0Answers: 0
edited July 2011 in General
Hello,

I need to use oTable.fnOpen inside fnDrawCallback.

[code]
oTable = $(".dataTable").dataTable({
"fnDrawCallback": function (oSettings) {
oTable.fnOpen(this, "some text", 'details');
}
});
[/code]

How can I do it?

Thank's
Andrey.

Replies

  • victorovictoro Posts: 5Questions: 0Answers: 0
    You can declare another variable from within fnDrawCallback like so:

    [code]
    oTable = $(".dataTable").dataTable({
    ...
    "fnDrawCallback": function () {
    var nTr = \$(".dataTable tbody tr"),
    checked = \$('input:radio[name=reporttype]:checked').val(),
    thisTable = \$('.dataTable').dataTable(); //<----- Instead of oTable
    if (checked == 'closed') {
    nTr.each(function() {
    if (thisTable.fnIsOpen( this )) {
    thisTable.fnClose( this );
    }
    }
    } else { // Toggle is open
    nTr.each(function() {
    if (!thisTable.fnIsOpen( this )) {
    thisTable.fnOpen( this );
    }
    }
    }
    });
    [/code]

    I'm toggling all hidden rows and need to make sure I'm closed or open when the table is refreshed.
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    The easiest way is using the 'this' keyword - DataTables callback functions are executed with the instance's scope, so you can simply do:

    [code]
    oTable = $(".dataTable").dataTable({
    "fnDrawCallback": function (oSettings) {
    this.fnOpen(this, "some text", 'details');
    }
    });
    [/code]

    Allan
  • gungnirgungnir Posts: 6Questions: 0Answers: 0
    edited August 2012
    i coppied my question to new thread that i just opened: http://www.datatables.net/forums/discussion/11228/redraw-and-fnopen
This discussion has been closed.