json response is not rendering on jquery data table

json response is not rendering on jquery data table

avi@aruneshavi@arunesh Posts: 8Questions: 3Answers: 0
edited April 2016 in Free community support

i'm trying to show a json response from server side to a jquery data table. but it's unable to render on the data table . i can see the response in chrome when i inspect it .
my response is like :-
[
{
"id": 22,
"name": "FPS-T25831236-1450251690209",
"lastUpdated": 1450251690213,
"createdBy": "Janaki",
"onBoarded": 1450251668000,
"activeFlag": true,
"createdBySafeId": "UC192791",
"sourceApplication": "FPS",
"subSource": "T25831236",
"type": "orderid",
"tag": [
"Arunesh",
"mamatha"
],
"comment": null,
"privateNote": true,
"reference": [
"T25831111"
],
"expiryDate": 1606630852
},
{
"id": 23,
"name": "FPS-T25831236-1450251728342",
"lastUpdated": 1450251728347,
"createdBy": "Janaki",
"onBoarded": 1450251668000,
"activeFlag": true,
"createdBySafeId": "UC192791",
"sourceApplication": "FPS",
"subSource": "T25831236",
"type": "orderid",
"tag": [
"Arunesh",
"mamatha"
],
"comment": null,
"privateNote": true,
"reference": [
"T25831111"
],
"expiryDate": 1606630852
}
]

and my javascript code is :-

$(function() { $( "#customerDialog" ).dialog({ autoOpen: false, title: "Customers", hide: "explode", modal: true, width: 500 }); $('#custTable').dataTable({ bJQueryUI: true, "processing": true, "serverSide": true, "contentType": "application/json", "dataType": "jsonp", "bStateSave": false, "bAutoWidth": false, "sAjaxSource": "http://url", "sAjaxDataProp": '', "crossDomain":true, "aoColumns": [{ "mData":"createdBy" },{ "mData": "createdBySafeId" },{ "mData": "lastUpdated" },{ "mData": "tag", "render": function(d) { return d.join(", ") } }], "fnServerData" : function(sSource, aoData, fnCallback) { $.getJSON(sSource, aoData, function(json) { map = {}; map["aaData"] = json; fnCallback(map); }); } }); $( "#opener" ).click(function() { $( "#customerDialog" ).dialog( "open" ); $('#customerDialog').dialog("widget").position({ }); }); });

and the html code :-
<body>
<!-- HTML -->
<div id="customerDialog">

createdBycreatedBySafeId Last modifiedTag

</div>
<button id="opener">Open Dialog</button>
</body>

This question has an accepted answers - jump to answer

Answers

  • avi@aruneshavi@arunesh Posts: 8Questions: 3Answers: 0
    edited April 2016

    sorry ,, this is the formatted javascript code

    '''
         $(function() {
            $( "#customerDialog" ).dialog({
               autoOpen: false, 
               title: "Customers",
               hide: "explode",
               modal: true,
               width: 500              
            });
    
            $('#custTable').dataTable({
               bJQueryUI: true,
              "processing": true,
              "serverSide": true,
              "contentType": "application/json",
              "dataType": "jsonp",
              "bStateSave": false,
              "bAutoWidth": false,
              "sAjaxSource": "http://url,
              "sAjaxDataProp": '',
              "crossDomain":true,
              "aoColumns": [{
                "mData":"createdBy"
              },{
                "mData": "createdBySafeId"  
              },{
                "mData": "lastUpdated"
              },{
                "mData": "tag",
                "render": function(d) {
                return d.join(", ")
                }
    
              }],
              "fnServerData" : function(sSource, aoData, fnCallback) {
            $.getJSON(sSource, aoData, function(json) {
            map = {};
            map["aaData"] = json;
            fnCallback(map);
            });
            }
            });
    
            $( "#opener" ).click(function() {
               $( "#customerDialog" ).dialog( "open" );
                $('#customerDialog').dialog("widget").position({
    
                });
            });
         });
    ''
    
  • allanallan Posts: 61,822Questions: 1Answers: 10,127 Site admin
    Answer ✓

    "sAjaxDataProp": '',

    but

    map["aaData"] = json;

    Seems like you should just be returning json if its an array.

    Also worth pointing out you are using a lot of legacy options such as fnServerData etc there.

    Allan

  • avi@aruneshavi@arunesh Posts: 8Questions: 3Answers: 0

    thanks allan , i removed the fnServerData function and now it's working fine ..
    i was doin it wrong i guess

This discussion has been closed.