DataTables not paginating - using ajax

DataTables not paginating - using ajax

lschneidermanlschneiderman Posts: 17Questions: 5Answers: 0

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" }
]
} );

https://newsinteractive.post-gazette.com/hospital-pt/

Can anyone tell me what I'm doing wrong to parse the data?

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Duplicate of this thread - please don't repeat.

    As we said before, you need to follow the protocol here. Look at the Ajax tab on this example for what the format should be.

    Colin

Sign In or Register to comment.