Datatables JSON Source

Datatables JSON Source

jcrawfordjcrawford Posts: 172Questions: 0Answers: 0
edited October 2011 in General
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

Replies

  • jcrawfordjcrawford Posts: 172Questions: 0Answers: 0
    ok solved this myself by using: "sAjaxDataProp": "output.aaData".

    Great work on this Allen, I am continuously impressed :)
  • jcrawfordjcrawford Posts: 172Questions: 0Answers: 0
    ok so while I have solved this by adding the sAjaxDataProp it caused an issue with pagination. It now allows me to click page 2 when one does not exist.

    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]
  • jcrawfordjcrawford Posts: 172Questions: 0Answers: 0
    thoughts? This paging error cannot be lived with if there is no way to resolve this I will have to go back to the other method of not embedding the information.
  • jcrawfordjcrawford Posts: 172Questions: 0Answers: 0
    for the time being I have gone back to the old way of outputting the table, that fixed the pagination issue so it might be a bug in the DataTables code causing that issue.
This discussion has been closed.