I'm using DataTables to display data returned from an ajax call. DataTables returns the data, but without dividing it into pages and at the bottom, it says, "Showing 0 to 0 of 0 entries (filtered from NaN total entries)" and the buttons at the bottom say, "Previous 1 2 3 4 5 ... NaN Next". So something isn't right, but I'm not sure what.
The data is returned from a PHP page with a sql call in this format:
[{hospital_name: "Advanced Surgical", raw_description: "Removal of breast lesion",…},…]
[0 … 99]
0: {hospital_name: "Advanced Surgical", raw_description: "Removal of breast lesion",…}
full_payer_name: "Aetna Auto: Medical OP"
hospital_name: "Advanced Surgical"
plan_type: "Commercial"
price: "$2,968.40"
raw_description: "Removal of breast lesion"
...(136 records in the same format as 0 above)
Here is my DataTables call:
$('#results').DataTable( {
"processing": true,
"serverSide": true,
searching: false,
"ajax": {
"url": "./php/getDataForCode.php",
"type": "POST",
"data": {code: $code}, //a variable that I pass to the query
"dataSrc": ""
},
columns: [
{ title: "Hospital", data: "hospital_name" },
{ title: "Description", data: "raw_description" },
{ title: "Insurer", data: "full_payer_name" },
{ title: "Insurer type", data: "plan_type"},
{ title: "You Pay", data: "price" }
]
} );
Can anyone tell me what I'm doing wrong to parse the data?
serverSide: trueoption. So, is your server-side code handling pagination (and filtering and sorting)? When you use this option, DataTables no longer handles any of these functions. Instead it delegates all of these to the server (to allow very large data sets to be handled). See here for some background notes, with links to documentation and examples. - andrewJamesserverSide: true? Do you have thousands/millions of rows of data? - andrewJames