Setting fnDrawCallback externally

Setting fnDrawCallback externally

jocapcjocapc Posts: 45Questions: 0Answers: 0
edited March 2011 in General
Hi,

I'm creating some plugin that uses datatables with jEditable and I need to put jEditable initialization code in fnDrawCallback function. Problem is that I would like to create generic plugin that will dinamically check whether the datatables work in serverside mode, and if so it should override fnDrawCallback function.

I'm trying to set the fnDrawCallback function but not in dataTable() parameters but externally from another function that belongs to my plugin. Problem is that I cannot access and set this function. This is a part of code I have:

I have reference to the datatable object:

var oTable = $('#myDataTable').dataTable();

...

In some callback function that can see variable oTable I have following code:

if (oTable.dataTableSettings[0].bAjaxDataGet) {
alert("server side processing");
oTable.fnDrawCallback = function () { alert('drawn callback'); };
//$(oTable).fnDrawCallback = function () { alert('drawn callback'); };
//jQuery.fn.dataTableExt.oApi.fnDrawCallback = function () { alert('drawn callback'); };
//oTable.dataTableSettings[0].oApi.fnDrawCallback = function () { alert('drawn callback'); };
}

oTable.dataTableSettings[0].bAjaxDataGet succeed to determine whether the datatable is in serverside mode and this is fine (alert is shown). Now, using this information I want to override fnDrawCallback so I can apply jEditable on new cells but this code does not work.
Three other commented lines were unsuccesful attempts to set this function.

In debbuger I find aoDrawCalback array but I'm not sure should I use it and how.

Could you please help me with this?

Thanks,
Jovan

Replies

  • jocapcjocapc Posts: 45Questions: 0Answers: 0
    I found an answer. I used something like:

    if (oTable.fnSettings().bAjaxDataGet) {
    oTable.fnSettings().aoDrawCallback.push({
    "fn": function () {
    fnApplyEditable(oTable.fnGetNodes());
    },
    "sName": "fnApplyEditable"
    });
    }

    It works for me but could you cofirm that this is a proper way to do it?

    Thanks,
    Jovan
This discussion has been closed.