I'm having a problem getting certain parts of a JSON array to display in a datatable.
Here is 1 section of the array.
[
{
"description": "Testing",
"lineStatus": "OK",
"persistent": true,
"pkgLineId": 102,
"pkgLineTree": {
"class": "models.PkgLineTree",
"entityId": 1,
"persistent": true,
"pkgLineTreeId": 1,
"treeId": {
"class": "models.Tree",
"entityId": 61,
"name": "Test",
"parentId": {
"class": "models.Tree",
"entityId": 57,
"name": "East",
"parentId": {
"class": "models.Tree",
"entityId": 52,
"name": "Test3",
"parentId": null,
"persistent": true,
"treeId": 52,
"webname": "coke"
},
"persistent": true,
"treeId": 57,
"webname": "east"
},
"persistent": true,
"treeId": 61,
"webname": "collegepark"
}
},
"shortname": "Line 1A",
"statusStamp": 1305726508000,
"timezone": "US/Eastern",
"webname": "line1a"
},
Here is my datable javascript.
$(window).load(function() {
var insertedTable = $('#pkgLineTable').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"bPaginate": true,
"bLengthChange": true,
"bFilter": true,
"bSort": false,
"bInfo": true,
"bAutoWidth": false,
"bProcessing": true,
"bServerSide": false,
"sAjaxSource": 'json/pkglinelist',
"fnServerData": fnServerObjectToArray(['shortname', 'description', 'lineStatus', 'statusStamp'])
});
});
Heres is my callback function.
fnServerObjectToArray = function (aElements) {
return function (sSource, aaData, fnCallback) {
$.ajax({
"dataType": 'json',
"type": "GET",
"url": sSource,
"data": aaData,
"success": function (json) {
var a = [];
$.each(json, function(index, item) {
var inner = [];
for (var i = 0, iLen = aElements.length; i < iLen; i++) {
inner.push(item[aElements[i]]);
}
a.push(inner);
});
json.aaData = a;
fnCallback(json);
}
});
}
}
I can plot certain parts of the JSON array fine. As you can see, things like description, lineStatus, and statusStamp work fine. If I dig into it it doesn't work. This is what I have tried.`
"fnServerData": fnServerObjectToArray(['pkgLineTree.class', 'pkgLineTree.entityId', 'lineStatus', 'statusStamp'])
I'm trying to get to more information lower into the array. It's not working. I'm guessing it may have something to do with the callback function.
If I try those values I get this back.
Datatables warning: requested unknown parameter '0' for the datasource on row '0'.
Just wondering what is going on here. Thanks a lot.