Datatables JSON Source
Datatables JSON Source
Currently I have been using some PHP to output json in the format that DataTables requires
[code]
{
"sEcho": 1,
"iTotalRecords": "1",
"iTotalDisplayRecords": "1",
"aaData": [
[
"10852",
"2011-10-19 15:55:25",
"DEBIT-StorePurchase",
"20",
"80",
""
]
]
}
[/code]
However due to our application design (mostly an api) we can no longer echo the data directly because of output buffering.
What we have to do is something like this
[code]
$this->setResponseParam('output', $data);
[/code]
The above code does all the json encoding, etc but requires that it be output like so
[code]
{
"output": {
"sEcho": 1,
"iTotalRecords": "1",
"iTotalDisplayRecords": "1",
"aaData": [
[
"10852",
"2011-10-19 15:55:25",
"DEBIT-StorePurchase",
"20",
"80",
""
]
]
}
}
[/code]
Is there a way to tell DataTables to use the value of the "output" or whatever we name it?
Thanks,
Joseph Crawford
[code]
{
"sEcho": 1,
"iTotalRecords": "1",
"iTotalDisplayRecords": "1",
"aaData": [
[
"10852",
"2011-10-19 15:55:25",
"DEBIT-StorePurchase",
"20",
"80",
""
]
]
}
[/code]
However due to our application design (mostly an api) we can no longer echo the data directly because of output buffering.
What we have to do is something like this
[code]
$this->setResponseParam('output', $data);
[/code]
The above code does all the json encoding, etc but requires that it be output like so
[code]
{
"output": {
"sEcho": 1,
"iTotalRecords": "1",
"iTotalDisplayRecords": "1",
"aaData": [
[
"10852",
"2011-10-19 15:55:25",
"DEBIT-StorePurchase",
"20",
"80",
""
]
]
}
}
[/code]
Is there a way to tell DataTables to use the value of the "output" or whatever we name it?
Thanks,
Joseph Crawford
This discussion has been closed.
Replies
Great work on this Allen, I am continuously impressed :)
This happened on all of my tables when I converted them to use the sAjaxDataProp. Any thoughts why this would happen?
Here is some sample output from one of my ajax sources
[code]
{
"output": {
"sEcho": 1,
"iTotalRecords": "2",
"iTotalDisplayRecords": "2",
"aaData": [
[
"1",
"coins-fif",
"test",
"45dfg9809fgd",
"2011-10-20 00:00:00",
"2011-10-31 00:00:00",
"2011-10-31 00:00:00",
"20",
"80",
"10"
],
[
"2",
"bucks-fif",
"another test",
"453lkjljl345",
"2011-10-01 00:00:00",
"2011-10-20 00:00:00",
"2011-10-20 00:00:00",
"35",
"140",
"20"
]
]
}
}
[/code]