sAjaxDataProp

sAjaxDataProp

bxp8561bxp8561 Posts: 3Questions: 0Answers: 0
edited July 2013 in DataTables 1.9
Hello
I am using the following code for dataTables. i am getting aData is undefined error
Pls help...
[code]
function populateValueAddTable() {
valueAddOTable = $('#valueAddTable').dataTable({
"bDestroy" : true,
"bServerSide" : false,
"bProcessing" : true,
"sAjaxDataProp" : "list.values",
"sAjaxSource" : "rs/services/json/getValueAdd",
"sScrollY" : 200,
"bJQueryUI" : true,
"sPaginationType" : "full_numbers",
"aoColumns" : [ {
"sTitle" : "ID",
"mDataProp" : "id"
}]
});

}
[/code]
and JSON is
[quote]
{
"list": [
{
"values": [
{
"id": 1,
"entryDate": "12/12/12",
"purpose": "yes",
"workStream": "BASIS",
"details": "Details",
"benefits": "Benefits",
"plannedImplementationDate": "12/10/12",
"proposedBy": "bxp8561"
},
{
"id": 14,
"entryDate": "12/12/13",
"purpose": "no",
"workStream": "BASIS",
"details": "New",
"benefits": "money",
"plannedImplementationDate": "12/1/13",
"proposedBy": "bxp8561"
}
]
}
]
}
[/quote]

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    list is an array, not an object. So you could use `list.0.values` to get the first entry in the list array (which is the object with the values property)

    Allan
  • bxp8561bxp8561 Posts: 3Questions: 0Answers: 0
    Allan

    if i were to remove the headers from the JSON like this, how should i write the datatable JS method?
    I dont want to do a loop...
    [code]
    [
    {
    "id": 1,
    "entryDate": "12/12/12",
    "purpose": "yes",
    "workStream": "BASIS",
    "details": "Details",
    "benefits": "Benefits",
    "plannedImplementationDate": "12/10/12",
    "proposedBy": "bxp8561"
    },
    {
    "id": 14,
    "entryDate": "12/12/13",
    "purpose": "no",
    "workStream": "BASIS",
    "details": "New",
    "benefits": "money",
    "plannedImplementationDate": "12/1/13",
    "proposedBy": "bxp8561"
    }
    ]
    [/code]
  • bxp8561bxp8561 Posts: 3Questions: 0Answers: 0
    Ok i did like this
    [code]
    function populateValueAddTable() {
    valueAddOTable = $('#valueAddTable').dataTable({
    "bDestroy" : true,
    "bServerSide" : false,
    "bProcessing" : true,
    "sAjaxSource" : "rs/services/json/getValueAdd",
    "sScrollY" : 200,
    "bJQueryUI" : true,
    "sPaginationType" : "full_numbers",
    "aoColumns" : [ {
    "sTitle" : "Entry Date",
    "mData" : "entryDate"
    }, {
    "sTitle" : "Purpose",
    "mData" : "purpose"
    }, {
    "sTitle" : "Work Stream",
    "mData" : "workStream"
    }, {
    "sTitle" : "Details",
    "mData" : "details"
    }, {
    "sTitle" : "Benefits",
    "mData" : "benefits"
    }, {
    "sTitle" : "Planned Implementation Date",
    "mData" : "plannedImplementationDate"
    }, {
    "sTitle" : "Proposed By",
    "mData" : "proposedBy"
    } ],
    "fnServerData" : function(sSource, aoData, fnCallback) {
    $.getJSON(sSource, aoData, function(json) {
    map = {};
    map["aaData"] = json;
    fnCallback(map);
    });
    }
    });
    [/code]
    and my json is
    [code]
    [{"id":1,"entryDate":"12/12/12","purpose":"yes","workStream":"BASIS","details":"Details","benefits":"Benefits","plannedImplementationDate":"12/10/12","proposedBy":"bxp8561"},{"id":14,"entryDate":"12/12/13","purpose":"no","workStream":"BASIS","details":"New","benefits":"money","plannedImplementationDate":"12/1/13","proposedBy":"bxp8561"},{"id":15,"entryDate":"12/12/13","purpose":"no","workStream":"BASIS","details":"New","benefits":"money","plannedImplementationDate":"12/1/13","proposedBy":"bxp8561"},{"id":16,"entryDate":"12/12/13","purpose":"no","workStream":"BASIS","details":"New","benefits":"money","plannedImplementationDate":"12/1/13","proposedBy":"bxp8561"},{"id":17,"entryDate":"12/12/13","purpose":"no","workStream":"BASIS","details":"New","benefits":"money","plannedImplementationDate":"12/1/13","proposedBy":"bxp8561"},{"id":18,"entryDate":"12/12/13","purpose":"no","workStream":"BASIS","details":"New","benefits":"money","plannedImplementationDate":"12/1/13","proposedBy":"bxp8561"},{"id":19,"entryDate":"12/12/13","purpose":"no","workStream":"BASIS","details":"New","benefits":"money","plannedImplementationDate":"12/1/13","proposedBy":"bxp8561"},{"id":20,"entryDate":"12/12/13","purpose":"no","workStream":"BASIS","details":"New","benefits":"money","plannedImplementationDate":"12/1/13","proposedBy":"bxp8561"},{"id":21,"entryDate":"12/12/13","purpose":"no","workStream":"BASIS","details":"New","benefits":"money","plannedImplementationDate":"12/1/13","proposedBy":"bxp8561"},{"id":22,"entryDate":"12/12/13","purpose":"no","workStream":"BASIS","details":"New","benefits":"money","plannedImplementationDate":"12/1/13","proposedBy":"bxp8561"},{"id":23,"entryDate":"12/12/13","purpose":"no","workStream":"BASIS","details":"New","benefits":"money","plannedImplementationDate":"12/1/13","proposedBy":"bxp8561"}]
    [/code]
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    An alternative is to use sAjaxDataProp and set it to an empty string to tell DataTables to expect an array rather than an object.

    Allan
This discussion has been closed.