"aoData is null" error

"aoData is null" error

MinervaMinerva Posts: 22Questions: 0Answers: 0
edited March 2012 in General
Hello,
I need some help debugging a "aoData is null or not an object" in the following function. I took the function apart and pasted in each section piece-by-piece to see where it croaks. It doesn't like fnAddData. However, I use this same basic code/syntax on other pages without issue. I can't display this page on a public webserver because it is part of a Powerchart page (hospital electronic patient chart).

I have other columns to include in the datatable but for now am keeping it simple and just including two. I left my commented-out alert boxes which I used to verify the rest of the code is executing without issue (it is).

Thank you for any ideas.

[code]function DocumentsTable() {

// XMLCclRequest is the Powerchart version of XMLHttpRequest
var DocumentInfo = new XMLCclRequest();

// When our request object has changed (is open):
DocumentInfo.onreadystatechange = function () {
// alert('test'); // runs three times

// Verify that we have data to work with:
if (DocumentInfo.readyState == 4 && DocumentInfo.status == 200) {
//alert('test readystate'); // runs one time

// Convert returned string to JSON object (eval):
var msgDoc = DocumentInfo.responseText;
if (msgDoc !== undefined && msgDoc !== null) {
var jsonDoc = eval("(" + msgDoc + ")");
//alert ('convert to JSON'); // runs one time
}

// Verify we successfully converted to a JSON object:
if (jsonDoc && jsonDoc.DATAREC.LIST && jsonDoc.DATAREC.LIST.length > 0) {
//alert ('json datarec list'); // runs one time

$('#DocTable').html(' ');

// define datatable/settings:
oTable = $("#DocDataTable").dataTable({
"aoColumns": [
{ "sTitle": "OrderID", "bVisible": false },
{ "sTitle": "Date", "sWidth": "110px", "bSortable": true }
],
"bDeferRender": true,
"oLanguage": { "sLengthMenu": 'Display 5'+
'1015'+
'2030'+
'All records'
}
}); // end var oTable definition

//alert('list len is: ' + jsonDoc.DATAREC.LIST.length) // 2

// loop thru recordset and append each row to the oTable datatable:
for (var i = 0; i < jsonDoc.DATAREC.LIST.length; i++) {

// Error occurs when fnAddData code is included in the function
// "aoData is null or not an object"
oTable.fnAddData([
jsonDoc.DATAREC.LIST[i].ORDER_ID,
jsonDoc.DATAREC.LIST[i].ORDER_DT
], false);

oTable.fnDraw();

} // end for loop

} //end if (jsonDoc &&...
else {
$('#DocTable').html('No information found')
} // else

}; //end if (DocumentInfo.readyState === 4 &&...

} //end DocumentInfo.onreadystatechange

// Call the ccl progam and send the parameter string:
DocumentInfo.open("GET", "MEMIL_MPAGE_MEDS_REC");
DocumentInfo.send("^MINE^, value($VIS_Encntrid$), value($PAT_Personid$)");
} //end DocumentsTable ()[/code]

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    This error tends to mean that the settings object has been lost for one reason or another. Does this work on first page load and then not again?

    I wonder if you need to add a destroy option in there to clean out old tables:

    [code]
    if ( $.fn.dataTableSettings.length > 0 ) {
    $("#DocDataTable").dataTable().fnDestroy();
    }

    $('#DocTable').html(' ');
    [/code]

    (so adding the destroy just before you add the table HTML again).

    Allan
  • MinervaMinerva Posts: 22Questions: 0Answers: 0
    Hi Allan. I added the code, closed/reopened Powerchart and tried again. I'm still getting the same error on the same line (fnAddData).
  • MinervaMinerva Posts: 22Questions: 0Answers: 0
    The plot thickens. I compared the html file for this powerchart page to one of its siblings that runs fine. My new page was missing a reference to jquery.dataTables.delayedRendering.js so I added that to see if I would get different results when loading the page.

    I have a different error now: "aoColumns is null or not an object" and peculiarly it is supposedly erroring out on line 2575 (my .js file has only 79 lines). How is that possible (not sure what that is revealing to me)?

    The included .js files are:
    -- jquery-1.6.min.js
    -- jquery-ui.min.js
    -- jquery.dataTables.min.js
    -- jquery.dataTables.delayedRendering.js
    -- medsrec_mpage.js (this is where my function lives)
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    What is in jquery.dataTables.delayedRendering.js ? That's not a file I'm familiar with.

    When you get the error - could you try using the DataTables debugger please ( http://debug.datatables.net ) so we can see what the state of the table is.

    Thanks,
    Allan
  • MinervaMinerva Posts: 22Questions: 0Answers: 0
    I'm not sure how to use the bookmarklet inside PowerChart. Although it is running on IE, you don't have any of the normal browser options. All the menus and shortcuts are specific to the patient chart. Let me ask around and see if anyone knows how to make this work.
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Ah bummer okay - hopefully someone will know! Does this happen on the first run of your code, or does it need to run the DocumentsTable() function twice before the error occurs?

    Allan
  • MinervaMinerva Posts: 22Questions: 0Answers: 0
    I don't have the option to run this code in a normal web browser. Sorry. I'm going to let this sit a day and see if maybe I can figure it out tomorrow. When I do, I'll post a response here of what I changed. Thanks for your time and ideas.
  • MinervaMinerva Posts: 22Questions: 0Answers: 0
    P.S. Just saw your question - the error happens on the initial load of the page/first time through the DocumentsTable() function.
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Its very odd indeed.

    What happens if you call:

    > oTable.fnDraw();

    Just after you initialise the table (i.e. before the for loop)? Does that work - I'm going to guess not...

    Allan
  • MinervaMinerva Posts: 22Questions: 0Answers: 0
    Interesting. If I do that I get "oFeatures is null or not an object"

    BTW, I removed that unknown/mystery delayedRendering.js file. I do not know what the file I was comparing to is using it for. I'll save that mystery for another day.
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Okay so you can't do this:

    [code]
    oTable = $("#DocDataTable").dataTable();
    oTable.fnDraw();
    [/code]

    Very odd!

    If you use the console, how many objects are in the $.fn.dataTableSettings object - i.e.:


    [code]
    console.log( $.fn.dataTableSettings.length );
    oTable = $("#DocDataTable").dataTable();
    console.log( $.fn.dataTableSettings.length );
    oTable.fnDraw();
    [/code]

    The settings object is being lost - but I don't know why, I'd probably need to the see page I'm afraid.

    Allan
  • MinervaMinerva Posts: 22Questions: 0Answers: 0
    I let this sit over the weekend until this morning so I could look at it fresh. I pieced the page together again from "scratch" (using a neighboring, functional page as a referencee) and it appears to be functioning fine now.

    I also read this thread - http://datatables.net/forums/discussion/2586/call-datatables-again-after-ajax/p1 - and double checked the info in my html file. At some point on Friday the div name in the html file and its corresponding reference in the .js no longer matched, due to my constant tinkering of the js code. That was not the cause of the original error (aodata is null), but I'm pretty confident it was my final mistake on Friday (aofeatures is null).

    The moral of the story is to let it sit for a little while so you can look at it with fresh eyes.

    Thanks again for your time and expertise.
This discussion has been closed.