json Data not displayed on the datatable

json Data not displayed on the datatable

dshdsh Posts: 19Questions: 0Answers: 0
edited May 2011 in General
Hi,

I have customized my data in a json format accepted by Datatables. But i dont see any data on my tables.
Here is my code. Please let me know, if i am missing any steps here.

[code]
var oTable2 = $('#example2').dataTable( {
"bProcessing": true,
"bServerSide": true,
"bRetrieve": true,
"bDestroy": true,
"aoColumns": [{ "sName": "systemID"},
{ "sName": "clientID"},
{ "sName": "clientDesc"},
{ "sName": "clientName"},
{ "sName": "intentID"},
{ "sName": "vendorOutputLocationId"},
{ "sName": "outputLocDesc"},
{ "sName": "vendorOutputLocationDir"},
{ "sName": "systemName"},
{ "sName": "intentName"},
{ "sName": "clientActive"},
{ "sName": "intentActive"}],
"sAjaxSource": 'http:/getPostalFulfillment.json',
"fnServerData": function ( sSource, aoData, fnCallback ) {
/* Add some extra data to the sender */
aoData.push( { "name": "i", "value":$("#IntentIds option:selected").val()},
{ "name": "sort", "value": "systemName"},
{ "name": "filter", "value": "null"},
{ "name": "dir", "value": "ASC"}
)
var xhr = $.ajax( {
"dataType": 'json',
"type": "POST",
"url": sSource,
"data": aoData,
"async":false,
"success": function(response){
var json = response.result.model
alert("json: "+ json);
fnCallback(json);
}
});
}
} );

[/code]"

Thanks

Replies

  • dshdsh Posts: 19Questions: 0Answers: 0
    I have this vaid jason data:

    {
    "aaData": [
    [
    "00000000-0000-0000-0000-000000000016",
    "AF8D776E-3AD8-4CCE-A410-2C932C236A49",
    "Blue Shield of California",
    "78",
    "4",
    "Right Fax",
    "c:/touchengine/fax",
    "Apollo",
    "BSCA",
    "Provider Fax -Provider Alert",
    "true",
    "true"
    ],
    [
    "00000000-0000-0000-0000-000000000016",
    "F6EE191F-E512-4BE2-8FE2-D68D323C93C4",
    "State of Kansas",
    "78",
    "4",
    "Right Fax",
    "c:/touchengine/fax",
    "Apollo",
    "State of Kansas",
    "Provider Fax -Provider Alert",
    "true",
    "true"
    ],
    [
    "00000000-0000-0000-0000-000000000016",
    "AD498633-0B09-4F02-9524-B561A9C842C8",
    "BCBS of Michigan",
    "78",
    "4",
    "Right Fax",
    "c:/touchengine/fax",
    "Apollo",
    "BCBS of Michigan",
    "Provider Fax -Provider Alert",
    "true",
    "true"
    ],
    [
    "00000000-0000-0000-0000-000000000022",
    "AF8D776E-3AD8-4CCE-A410-2C932C236A49",
    "Blue Shield of California",
    "78",
    "null",
    "null",
    "null",
    "Care Alerts",
    "BSCA",
    "Provider Fax -Provider Alert",
    "true",
    "true"
    ],
    [
    "00000000-0000-0000-0000-000000000017",
    "AF8D776E-3AD8-4CCE-A410-2C932C236A49",
    "Blue Shield of California",
    "78",
    "4",
    "Right Fax",
    "c:/touchengine/fax",
    "PCMS",
    "BSCA",
    "Provider Fax -Provider Alert",
    "true",
    "true"
    ]
    ]
    }
  • dshdsh Posts: 19Questions: 0Answers: 0
    Hi,

    Anybody could please help me with this code.
    I tried in firefox, it does not like the variable "respose" on success.
    But still I can access that variable and get just the required json data from response.result.model .

    How that can be ?
  • allanallan Posts: 63,508Questions: 1Answers: 10,471 Site admin
    You've got server-side processing on ( bServerSide": true ), but you don't have the required return values for server-side processing ( http://datatables.net/usage/server-side ). I suspect from your json data, you don't want server-side processing, so just remove the bServerSide: true line. More information on the data source options here: http://datatables.net/usage/#data_sources

    Allan
  • dshdsh Posts: 19Questions: 0Answers: 0
    edited May 2011
    Hi Allan,

    Thank you so much for the response.

    I eliminated ( bServerSide": true ). Actually, Allan I also updated the succcess part of the Ajax call. Instead of using the "response" parameter, I replaced it with "json" parameter. Now i dont get that error "response unidentified" but i get another error: "json.aaData is undefined".

    This is the respose and json details , i am getting in firefox:
    ------------------------
    response:

    {"result":{"class":"xxx","model":"{\"aaData\":[[\"00000000-0000-0000-0000-000000000004\",\"802F156E-1A08-4EFC-85CD-DF3DF3A54500\",\"Rockwell Collins\",\"83\",\"null\",\"null\",\"null\",\"CorConnect\",\"Rockwell Collins\",\"Apollo Health Coaching Email \",\"true\",\"true\"]]}","requestURL":"http://getPostalFulfillment.json","timestamp":1305224837305}}

    -----------------------------
    JSON:

    result Object { class="xxx", model="{"aaData":[["00000000-0...ail 2","true","true"]]}", more...}

    class "xxx"

    model "{"aaData":[["00000000-0000-0000-0000-000000000004","802F156E-1A08-4EFC-85CD-DF3DF3A54500","Rockwell Collins","83","null","null","null","CorConnect","Rockwell Collins","Apollo Health Coaching Email 2","true","true"]]}"

    requestURL
    "http://getPostalFulfillment.json"

    timestamp
    1305224837305

    ----------------------------------

    Here is my updated code:

    [code]
    var oTable2 = $('#example2').dataTable( {
    "bProcessing": true,
    "bRetrieve": true,
    "bDestroy": true,
    "aoColumns": [{ "sName": "systemID"},
    { "sName": "clientID"},
    { "sName": "clientDesc"},
    { "sName": "clientName"},
    { "sName": "intentID"},
    { "sName": "vendorOutputLocationId"},
    { "sName": "outputLocDesc"},
    { "sName": "vendorOutputLocationDir"},
    { "sName": "systemName"},
    { "sName": "intentName"},
    { "sName": "clientActive"},
    { "sName": "intentActive"}],
    "sAjaxSource": 'http://getPostalFulfillment.json',
    "fnServerData": function ( sSource, aoData, fnCallback ) {
    /* Add some extra data to the sender */
    aoData.push( { "name": "i", "value":$("#IntentIds option:selected").val()},
    { "name": "sort", "value": "systemName"},
    { "name": "filter", "value": "null"},
    { "name": "dir", "value": "ASC"}
    )
    $.ajax( {
    "dataType": 'json',
    "type": "POST",
    "url": sSource,
    "data": aoData,
    "success": function(json){
    var json = json.result.model;
    alert("json: "+ json);
    //var test = json;
    //alert("test: "+ test);
    fnCallback(json);
    }
    });
    }
    } );
    });

    [/code]
  • allanallan Posts: 63,508Questions: 1Answers: 10,471 Site admin
    From the JSON data you need:

    json.result.model.aaData (or possibly json.model.aaData)

    Allan
  • dshdsh Posts: 19Questions: 0Answers: 0
    edited May 2011
    I get this error for both the options :-(


    "json is undefined" for:
    [code]
    $.ajax( {
    "dataType": 'json',
    "type": "POST",
    "url": sSource,
    "data": aoData,
    "success": function(json){
    var json = json.result.model.aaData;
    alert("json: "+ json);
    fnCallback(json);
    }
    });

    [/code]

    and "json.model is undefined" for:

    [code]
    $.ajax( {
    "dataType": 'json',
    "type": "POST",
    "url": sSource,
    "data": aoData,
    "success": function(json){
    var json = json.model.aaData;
    alert("json: "+ json);
    fnCallback(json);
    }
    });
    [/code]


    json.model is undefined
  • allanallan Posts: 63,508Questions: 1Answers: 10,471 Site admin
    Can you give me a link to your web-page please? That would make it much easier to understand what the problem is. Basically it looks like you just need to get the right json object member.

    Allan
  • dshdsh Posts: 19Questions: 0Answers: 0
    Allan,

    Please let me know, if there is a way i could send you some screenshots or the entire code.

    Thanks.
  • dshdsh Posts: 19Questions: 0Answers: 0
    edited May 2011
    I dont think u can access the link bcoz of vpn issues. sorry is there any other option ?
  • dshdsh Posts: 19Questions: 0Answers: 0
    The variable json on alert gives me:

    json: {"aaData":[["00000000-0000-0000-0000-000000000016","31E8AB83-AC7D-458C-9794-019AAD134946","State Farm","94","null","null","null","Apollo","State Farm","Member Announcement State Farm Retiree","true","true"],["00000000-0000-0000-0000-000000000005","31E8AB83-AC7D-458C-9794-019AAD134946","State Farm","94","null","null","null","TRAX DM","State Farm","Member Announcement State Farm Retiree","true","true"]]}

    This looks like json is having a valid data.

    Then why does it still complain:

    "json.aaData is undefined"

    [code]
    $.ajax( {
    "dataType": 'json',
    "type": "POST",
    "url": sSource,
    "data": aoData,
    "success": function(json){
    var json = json.result.model;
    alert("json: "+ json);
    fnCallback(json);
    }
    });
    [/code]
  • allanallan Posts: 63,508Questions: 1Answers: 10,471 Site admin
    Yup that looks valid to me - so I'm not sure what the issue is I'm afraid without being able to see it in action. You could have a look at my working example which shows the JSON reply DataTables expects by default: http://datatables.net/examples/data_sources/js_array.html

    Allan
  • dshdsh Posts: 19Questions: 0Answers: 0
    edited May 2011
    Hey Allan,

    I got it working using "eval", Thanks so much for your quick replies.

    [code]
    $.ajax( {
    "dataType": 'json',
    "type": "POST",
    "url": sSource,
    "data": aoData,
    "success": function(json){
    var json = eval('('+ json.result.model + ')');
    alert("json: "+ json);
    fnCallback(json);
    }
    });
    [/code]
This discussion has been closed.