Row details shows "undefined"...

Row details shows "undefined"...

jQuery_userjQuery_user Posts: 27Questions: 0Answers: 0
edited January 2011 in General
Hi Alan,

First of all, I thank you for creating such an elegant solution which is unmatched in my experience!

I have been using "Row details" http://www.datatables.net/examples/api/row_details.html

I modified fnFormatDetails() to use AJAX (getJSON)

I get "undefined" as output...

Here is the code:
[code]function fnFormatDetails ( oTable, nTr )
{
var aData = oTable.fnGetData( nTr );

$.getJSON("",
function(data) {
var sOut = '';
sOut+=...
sOut += '';

return sOut;

});
}[/code]

When I alert sOut value, I can see the table with headers and data...
The AJAX code works fine as I can see well formed JSON string in firebug(alson in JSON tab). Can you tell where am I going wrong?

Replies

  • jQuery_userjQuery_user Posts: 27Questions: 0Answers: 0
    edited January 2011
    I fixed this by setting $.ajaxSetup parameter: async: false,

    The following code works!

    [code]function fnFormatDetails ( oTable, nTr )
    {
    var aData = oTable.fnGetData( nTr );
    var sOut = '';
    $.ajaxSetup({ // Since getJSON is asynchronous by default set async: false
    async: false,
    "error":function() {
    alert("error");
    }});

    $.getJSON("",
    function(data) {
    sOut+=...
    sOut += '';
    });
    return sOut;
    }[/code]
  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin
    Yup - because the Ajax call is async you would need to call back to the TR element and insert the text yourself, rather than having DataTables do it. You could return 'Loading...' and then replace that when the $.getJSON is complete. Or async: false works as well.

    Allan
This discussion has been closed.