How to render my JSON data into table
How to render my JSON data into table
ilayaraja
Posts: 5Questions: 0Answers: 0
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?
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?
This discussion has been closed.
Replies
sEcho is sent from the client and gets incremented for each draw. Check your script.
[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]
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
is your JSON valid?? Use JSON LINT and validate the JSON
?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?