PHP json_encode($data)
PHP json_encode($data)
bbrindza
Posts: 329Questions: 78Answers: 1
Hello fellow travelers,
I have always use DataTable ssp scripts for my back end data source. However with the limitations of the ssp.class I cannot do complex SQL such as GROUP BY and SUM .
So I went with a PHP script the returns the json_encode($data) to the DataTable js .
However, I can get the data to load. I receive this error: "Uncaught TypeError: Cannot read property 'length' of undefined"
Below is my PHP array structure and DaTables AJAX
$data[] = array(
"PO_OrderNumber" => $row['APPONO'],
"payableNumber" => $row['APPAY#'],
"invoiceNumber" => $row['APINVC'],
"vendorNumber" => $row['APVEND'],
"vendorName" => $row['VMRMTN'],
"entryDate" => $row['APENDT'],
"itemNumber1" => $row['APIT01'],
"itemNumber2" => $row['APIT02'],
"itemNumber3" => $row['APIT03'],
"itemQuantity1" => $row['APQT01'],
"totalPayableAmount" => $row['APTLPA'],
"claimNumber" => $row['FDCLMN'],
"claimTotal" => $row['FCTOTAL'],
);
$(document).ready(function() {
$('#APAgingVsFreightClaimsTable').DataTable( {
ajax: {
url: "FreightClaims/AccountingReports/getAPAgingFreightClaimsData.php",
dataSrc: 'data'
},
columns: [
{ "data": "PO_OrderNumber" },
{ "data": "payableNumber" },
{ "data": "invoiceNumber" },
{ "data": "vendorNumber" },
{ "data": "vendorName" },
{ "data": "entryDate" },
{ "data": "itemNumber1" },
{ "data": "itemNumber2" },
{ "data": "itemNumber3" },
{ "data": "itemQuantity1" },
{ "data": "totalPayableAmount" },
{ "data": "claimNumber" },
{ "data": "claimTotal" }
]
} );
} );//END $(document).ready(function()
This question has an accepted answers - jump to answer
Answers
I'm not familiar with PHP so not sure of the structure returned. Please post the JSON response from the browser's network inspector tool.
Kevin
Sample of JSON response ..

You have
dataSrc: 'data'but the JSON is not in adataobject. You can either put the data in thedataobject or change theajax.dataSrcoption to bedataSrc: ''.Kevin
That worked. Thank you Kevin. First time I used this technique.