"aoData is null" error
"aoData is null" error
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]
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]
This discussion has been closed.
Replies
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
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)
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
Allan
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
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.
[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
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.