JSON - accessing returned data other than 'data'
JSON - accessing returned data other than 'data'
needmorecoffee
Posts: 2Questions: 1Answers: 0
Hi - I have a table working well from a POST and JSON response.
var myTable=$('#table_id').DataTable({
"ajax":{
"url": "lookup-ajax.php",
"type": "POST",
"dataType": "json",
"data": function ( d ) {return $('#stats_search').serialize();}
},
"columns": [
{"data": "age"},
{"data": "height"},
{"data": "weight"}
],
"order": [[ 1, "desc" ]],
"pagingType": "full_numbers",
"lengthMenu": [[50, 100, -1], [50, 100, "All"]]
});
The JSON is set out exactly as shown in your example Object data source
"columns" are used to access the "data" - but how can the other info returned be accessed such as "recordsTotal": 57 ?
This one is doing my head in?:-) Any suggestions welcome.
This question has accepted answers - jump to:
This discussion has been closed.
Answers
recordsTotal
and the like are only used when server-side processing is enabled.Allan
if you really need to you could use mytable.ajax.json() and that should give you the entire json response filled with anytihng you needed.. adding it in should be pretty simple if you do server side scripting, just create new entries in your response array and fill them with whatever you want (tho you shouldn't really need that without server-side, like allan said)
Thanks for aiming me in the right direction. I did find a solution that works very well!
We are searching a database of about 2Mil records, so we limit the results to 250, but still need to indicate to the client the total records available - we can now return this custom data as part of the JSON like follows - keep in mind I'm a self taught novice:-) So there is probably a better way, but this does work very well and very fast! It's amazing just how much faster these searches are without having to refresh the screen!
So happy with the results - I'm sending another contribution - just a little thanks for the great datatables resource!