How to render my JSON data into table

How to render my JSON data into table

ilayarajailayaraja Posts: 5Questions: 0Answers: 0
edited December 2012 in DataTables 1.9
As per the document here http://datatables.net/release-datatables/examples/data_sources/server_side.html i have implemented the server side code.

JS code
[code]
$('#datatable_paging').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "#### my php file path ####",


});
[/code]

I am getting JSON data as

[code]
{
"sEcho": 0,
"iTotalRecords": 19,
"iTotalDisplayRecords": "19",
"aaData": [
["1", "lovely", "lovely_alex@ispg.in"],
["2", "steve", "stev@yahoo.com"],
["46", "shemil", "shemil@ispg.in"],
["54", "dawood", "dawood_rang@ispg.in"],
["55", "pramith", "prami@gmail.com"],
["61", "muadth", "muad@hotmail.com"],
["62", "ahmed", "ahmed@gmail.com"],
["66", "ahmed1234", "amah@wantedsystems.com"],
["67", "ahmed12345", "admi@incogear.com"],
["74", "ramesh", "qamailtest@gmail.com"],
["78", "Manas", "mana@ispg.in"],
["81", "arunvarghe", "arunvar@gmail.com"],
["87", "userfour", "qamailtesti@gmail.com"],
["89", "salam", "abdus_salam@ispg.in"],
["90", "Qamail", "qamailtestin@gmail.com"],
["92", "madhavi", "madhavi_srin@ispg.in"],
["108", "ilayaraja", "ilayaraj@ispg.in"],
["109", "ilaya_selva", "ilayarajas@gmail.com"],
["111", "NaDaMuhammad", "profn@gmail.com"]

]
}
[/code]


Now i don't know how to display this result in table with Datatable pagination, Can somebody help me please?

Replies

  • girishmrgirishmr Posts: 137Questions: 0Answers: 0
    edited December 2012
    You are using serverside script and If sEcho is 0, there is an issue in your script.
    sEcho is sent from the client and gets incremented for each draw. Check your script.
  • ilayarajailayaraja Posts: 5Questions: 0Answers: 0
    My query string look like
    [code]?sEcho=1&iColumns=3&sColumns=&iDisplayStart=0&iDisplayLength=5&mDataProp_0=0&mDataProp_1=1.......
    [/code]

    While retrieving in php its not getting the actual value

    [code]
    $output = array(
    'sEcho' => intval($_GET['sEcho']), //taking 0
    'iTotalRecords' => $iTotal,
    'iTotalDisplayRecords' => $iFilteredTotal,
    'aaData' => array()
    );
    [/code]
  • girishmrgirishmr Posts: 137Questions: 0Answers: 0
    What are the values you are having for 'iTotalRecords' and 'iTotalDisplayRecords'. Does this match the number of records that gets pulled from the DB with your query.

    Sanity check: Does your DB structure is correctly defined for RI (if any) and column naming convention. I am asking this because for someone I had helped earlier had DB issues.
    Check the data you are passing to your script and its mapping to the correct columns. If possible share your scripts or run it thru' DT debugger
  • ilayarajailayaraja Posts: 5Questions: 0Answers: 0
    Yes i am having correct value for 'iTotalRecords' (20)and 'iTotalDisplayRecords'(20). Now alert is showing like [code]DataTables warning (table id = 'datatable_paging'): DataTables warning: JSON data from server could not be parsed. This is caused by a JSON formatting error.[/code]
  • girishmrgirishmr Posts: 137Questions: 0Answers: 0
    Check FAQ topic I get a JSON parsing error
    is your JSON valid?? Use JSON LINT and validate the JSON
  • ilayarajailayaraja Posts: 5Questions: 0Answers: 0
    Yes i did check in JSON lint, it's Valid JSON
  • girishmrgirishmr Posts: 137Questions: 0Answers: 0
    [quote]
    ?sEcho=1&iColumns=3&sColumns=&iDisplayStart=0&iDisplayLength=5&mDataProp_0=0&mDataProp_1=1.......
    [/quote]

    You should not be setting the sEcho value. As said earlier, this is set in DT plugin itself and gets incremented on every draw. Infact you need not set any of those values except for those you are passing for your query to fetch from the database.

    Can be more helpful if you can share your script/host it somewhere where we can check or use DT debugger?
This discussion has been closed.