fnDrawCallback not executing function

fnDrawCallback not executing function

pspencepspence Posts: 7Questions: 0Answers: 0
edited August 2010 in General
I am new to DataTables but greatly enjoying this fine work. I am just trying to get my callback function to work and am testing with an alert. The code below does not produce an alert when you click on a row. Ultimately I will want to run some server side php code but I seem to be missing something.

I have based this code on this thread:

http://datatables.net/forums/comments.php?DiscussionID=1838&page=1

[code]
$(document).ready(function() {


/* Init the table */
var oTable = $('#staff').dataTable({
bProcessing: true,
bServerSide: true,
sDom: '<"top"fp>rt<"bottom"li><"clear">',
sAjaxSource: "server_processing.php",
fnDrawCallback: function() {
clickRowHandler();
}
});
function clickRowHandler() {
$('#staff tbody tr').bind('click', function () {
alert();
});
}
});

[/code]

Replies

  • HenningHenning Posts: 3Questions: 0Answers: 0
    Have you found the solution yet?

    There are some things that should solve it:
    The fnDrawCallback takes oSettings as a parameter.
    All keys in the dataTable declaration should be enclosed in "" characters.
    To use an external function as the value, just type the function name, and declare ClickRowHandler = function(oSettings). Alternatively declare the function in-line as an anonymous function.

    Here are the two alternatives:

    [code]
    $(document).ready(function() {

    /* Init the table */
    var oTable = $('#staff').dataTable({
    bProcessing: true,
    bServerSide: true,
    sDom: '<"top"fp>rt<"bottom"li><"clear">',
    sAjaxSource: "server_processing.php",
    fnDrawCallback: ClickRowHandler
    });
    clickRowHandler = function(oSettings) {
    $('#staff tbody tr').bind('click', function () {
    alert();
    });
    }
    });
    [/code]

    or

    [code]

    $(document).ready(function() {


    /* Init the table */
    var oTable = $('#staff').dataTable({
    bProcessing: true,
    bServerSide: true,
    sDom: '<"top"fp>rt<"bottom"li><"clear">',
    sAjaxSource: "server_processing.php",
    fnDrawCallback: function(oSettings) {
    $('#staff tbody tr').bind('click', function () {
    alert();
    });
    }
    });
    });
    [/code]
  • HenningHenning Posts: 3Questions: 0Answers: 0
    Oops, in the first alternative, move the ClickRowHandler declaration to outside the document.ready declaration.
This discussion has been closed.