How to Render JSON data as OBJECT list NOT Array List

How to Render JSON data as OBJECT list NOT Array List

bhekstabheksta Posts: 6Questions: 1Answers: 0
  • File: jquery.dataTables.min.js
  • Version: 1.9.4

-- I have following all online documentation example on how to fetch data through AJAXSource...BUT NO luck

I have this JSON data format that I need to render as DataTable..

BUT then I get this error:
DataTables warning (table id = 'xxxxx'): Requested unknown parameter '0' from the data source for row 0

{"data":[{"Date":"2014-07-03 ","TotalPaidOk":"937","Total1stBilled":"939","TotalPending":"0","TotalFree":"1","TotalNoFunds":"2","TotalSysErrors":"0","TotalObs":"0","TotalObsSuccess":"0","TotalObsSuccessRands":".000000","DisplaySequence":1},{"Date":"2014-07-02 ","TotalPaidOk":"4297","Total1stBilled":"13334","TotalPending":"1","TotalFree":"2","TotalNoFunds":"10490","TotalSysErrors":"611","TotalObs":"37698","TotalObsSuccess":"5054","TotalObsSuccessRands":"10108.000000","DisplaySequence":2}....]}

**BUT this JSON format it does render it well
{"data":[["2014-07-03 ","937","939","0","1","2","0","0","0",".000000",1],["2014-07-02 ","4297","13334","1","2","10490","611","37698","5054","10108.000000",2],["2014-07-01 ","9482","13363","1","2","10449","641","47238","10468","20936.000000",2] ....]}

               /*begin*/

                    $('#testTable').dataTable( {
                       "aaData":data.data,
                       "sPaginationType": "bootstrap",
                       "bSort": false,
                       //"sScrollY": "600px",
                       //"bPaginate": false,
                       "oLanguage": {
                            "sLengthMenu": "_MENU_ records per page"
                       },
                        "aoColumns": [
                            {"bSortable": true, "asSorting": [ "desc" ] , "sWidth":"100px", "sTitle":"Date", "data":"Date"},
                            {"bSortable": true, "sTitle":"# Fully Paid", "data":"TotalPaidOk"},
                            {"bSortable": true, "sTitle":"# 1st Billed", "data":"Total1stBilled"},
                            {"bSortable": true, "sTitle":"# Pending", "data":"TotalPending"},
                            {"bSortable": true, "sTitle":"# Free", "data":"TotalFree"},
                            {"bSortable": true, "sTitle":"# No Funds", "data":"TotalNoFunds"},
                            {"bSortable": true, "sTitle":"# Sys Errors", "data":"TotalSysErrors"},
                            {"bSortable": true, "sTitle":"# Obs", "data":"TotalObs"},
                            {"bSortable": true, "sTitle":"# Obs Success", "data":"TotalObsSuccess"},                               
                            {"bSortable": true, "bSortable": true, "sTitle":"Obs Success (ZAR)"
                            , "data":"TotalObsSuccessRands", "sType":"currency"                            
                            },
                            {"bSortable": true, "asSorting": [ "asc", "desc" ] , "sTitle":"Sequence", "data":"DisplaySequence"},
                        ],

                        "aoColumnDefs": [
                        { "aDataSort": [ 10 ], "aTargets": [ 10 ] },

                            {                                                
                                "mRender": function ( data, type, row) {
                                         var mValue = parseFloat(0.00);
                                         mValue = parseFloat( data );
                                         if ( mValue > 0 ) {
                                           //mValue = Math.round(mValue);                                              
                                           return 'R' + mValue.toFixed(2);
                                         }else
                                          return '-'

                                         return 'R' + data;
                                },
                                "aTargets": [9]
                            },
                            {"bVisible": false,  "aTargets": [ 10 ] }
                        ]

                    } );

                    /*end*/
This discussion has been closed.