Data retrieved not shown.
Data retrieved not shown.
NathanielUnderwood
Posts: 7Questions: 0Answers: 0
Hi there,
i'm having weird behaviour with server side processing data, all the comunication with server and retrieving of the data is performed
succesfully but after getting the data from server the table keeps empty and clean, i'm almost sure that the json is well formed, firefug opens it without problem and if I set to falese the bServerSide option and use normal ajax the table fills itself succesfully
[code]
<!-- id -->
<!-- type_id -->
<!-- status_id -->
<!-- province_id -->
<!-- type_icon -->
<!-- status_icon -->
<!-- gender_icon -->
Name<!-- name -->
E-Mail<!-- email -->
Birthdate<!-- birthdate -->
Province<!-- province -->
Zipcode<!-- zipcode -->
<!-- id -->
<!-- type_id -->
<!-- status_id -->
<!-- province_id -->
<!-- type_icon -->
<!-- status_icon -->
<!-- gender_icon -->
Name<!-- name -->
E-Mail<!-- email -->
Birthdate<!-- birthdate -->
Province<!-- province -->
Zipcode<!-- zipcode -->
$(document).ready(function(){
$('#test_table').dataTable({
iDisplayLenght: 50,
bServerSide: true,
bJQueryUI: true,
bStateSave: true,
sPaginationType: "full_numbers",
sScrollY: "200px",
sAjaxSource: "/index/index",
sDom: '<"H"Tl>tS<"F"ip>',
sSortJUIAsc: "css_right sortAsc",
sSortJUIDesc: "css_right sortdesc",
sSortJUI: "css_right sortNoSort",
aoColumns: [
{ sName: "id", bVisible: false, bSortable: false },
{ sName: "type_id", bVisible: false, bSortable: false },
{ sName: "status_id", bVisible: false, bSortable: false },
{ sName: "province_id", bVisible: false, bSortable: false },
{ sName: "type_icon", bVisible: true, bSortable: false },
{ sName: "status_icon", bVisible: true, bSortable: false },
{ sName: "gender_icon", bVisible: true, bSortable: false },
{ sName: "name", bVisible: true, bSortable: true, sClass: "leftColumn" },
{ sName: "email", bVisible: true, bSortable: false },
{ sName: "birthdate", bVisible: true, bSortable: false, sClass: "centerColumn" },
{ sName: "province", bVisible: true, bSortable: false },
{ sName: "zipcode", bVisible: true, bSortable: false, sClass: "centerColumn" }
],
oTableTools: {
sSwfPath: "/swf/copy_cvs_xls_pdf.swf"
}
});
});
[/code]
and the server side code looks like this:
[code]
public function indexAction()
{
if($this->getRequest()->isXmlHttpRequest()) {
$sEcho = $this->getRequest()->getParam("iEcho");
$start = ($this->getRequest()->has("iDisplayStart")) ? $this->getRequest()->getParam("iDisplayStart") : 0;
$offset = ($this->getRequest()->has("iDisplayLength")) ? $this->getRequest()->getParam("iDisplayLength") : 100;
$colnum = $this->getRequest()->getParam("iColumns");
$data = Model_User::getTableData(array("start" => $start, "rows" => $offset));
$response = array(
"iTotalRecords" => Model_User::getTableDataCount(),
"iTotalDisplayRecords" => count($data),
"sEcho" => (int)$sEcho,
"sColumns" => "id,type_id,status_id,province_id,type_icon,status_icon,gender_icon,username,name,email,mobile,birthdate,province,zipcode",
"aaData" => $data
);
$this->_helper->json($response);
}
}
[/code]
i'm totally lost with this issue, any help will be appreciate.
Thanks in advance.
Diego.
i'm having weird behaviour with server side processing data, all the comunication with server and retrieving of the data is performed
succesfully but after getting the data from server the table keeps empty and clean, i'm almost sure that the json is well formed, firefug opens it without problem and if I set to falese the bServerSide option and use normal ajax the table fills itself succesfully
[code]
<!-- id -->
<!-- type_id -->
<!-- status_id -->
<!-- province_id -->
<!-- type_icon -->
<!-- status_icon -->
<!-- gender_icon -->
Name<!-- name -->
E-Mail<!-- email -->
Birthdate<!-- birthdate -->
Province<!-- province -->
Zipcode<!-- zipcode -->
<!-- id -->
<!-- type_id -->
<!-- status_id -->
<!-- province_id -->
<!-- type_icon -->
<!-- status_icon -->
<!-- gender_icon -->
Name<!-- name -->
E-Mail<!-- email -->
Birthdate<!-- birthdate -->
Province<!-- province -->
Zipcode<!-- zipcode -->
$(document).ready(function(){
$('#test_table').dataTable({
iDisplayLenght: 50,
bServerSide: true,
bJQueryUI: true,
bStateSave: true,
sPaginationType: "full_numbers",
sScrollY: "200px",
sAjaxSource: "/index/index",
sDom: '<"H"Tl>tS<"F"ip>',
sSortJUIAsc: "css_right sortAsc",
sSortJUIDesc: "css_right sortdesc",
sSortJUI: "css_right sortNoSort",
aoColumns: [
{ sName: "id", bVisible: false, bSortable: false },
{ sName: "type_id", bVisible: false, bSortable: false },
{ sName: "status_id", bVisible: false, bSortable: false },
{ sName: "province_id", bVisible: false, bSortable: false },
{ sName: "type_icon", bVisible: true, bSortable: false },
{ sName: "status_icon", bVisible: true, bSortable: false },
{ sName: "gender_icon", bVisible: true, bSortable: false },
{ sName: "name", bVisible: true, bSortable: true, sClass: "leftColumn" },
{ sName: "email", bVisible: true, bSortable: false },
{ sName: "birthdate", bVisible: true, bSortable: false, sClass: "centerColumn" },
{ sName: "province", bVisible: true, bSortable: false },
{ sName: "zipcode", bVisible: true, bSortable: false, sClass: "centerColumn" }
],
oTableTools: {
sSwfPath: "/swf/copy_cvs_xls_pdf.swf"
}
});
});
[/code]
and the server side code looks like this:
[code]
public function indexAction()
{
if($this->getRequest()->isXmlHttpRequest()) {
$sEcho = $this->getRequest()->getParam("iEcho");
$start = ($this->getRequest()->has("iDisplayStart")) ? $this->getRequest()->getParam("iDisplayStart") : 0;
$offset = ($this->getRequest()->has("iDisplayLength")) ? $this->getRequest()->getParam("iDisplayLength") : 100;
$colnum = $this->getRequest()->getParam("iColumns");
$data = Model_User::getTableData(array("start" => $start, "rows" => $offset));
$response = array(
"iTotalRecords" => Model_User::getTableDataCount(),
"iTotalDisplayRecords" => count($data),
"sEcho" => (int)$sEcho,
"sColumns" => "id,type_id,status_id,province_id,type_icon,status_icon,gender_icon,username,name,email,mobile,birthdate,province,zipcode",
"aaData" => $data
);
$this->_helper->json($response);
}
}
[/code]
i'm totally lost with this issue, any help will be appreciate.
Thanks in advance.
Diego.
This discussion has been closed.
Replies
But that's just a URL. Chances are good that it's fine.
What I don't see is where the response is being echoed back from the server. Since I'm not much of a PHP guy, though, I could just be misunderstanding what the $this->_helper->json($response) is doing.
If you open up Firebug or another debugging tool, can you see what the response body is on the client side? If it "looks" like JSON, copy it over into jsonlint.com to confirm.
the urls and redirect to the right controller and action, that url stands for controller index, action index, and the $this->_helper->json($response) line simply takes the $response, an array containing the data, converts it to json and pushs it to the browser without layout.
And yes, the json is well formed, firebug and JSONLint manage it without errors, the generated json is as follows, just retrieved only two records from database for readability purposes, checked with JSONLint:
[code]
{"iTotalRecords":373324,"iTotalDisplayRecords":2,"sEcho":0,"sColumns":"id,type_id,status_id,province_id,type_icon,status_icon,gender_icon,username,name,email,mobile,birthdate,province,zipcode","aaData":[["1","2","1","33","","","","Test","drin@antevenio.com","18\/08\/1975","Madrid","28045"],["2","1","1","33","","","","Test","diego.rin@gmail.com","18\/08\/1975","Madrid","28045"],["14330","1","3","10","","","","Montse Vergara","dissenysvergara@gmail.com","04\/10\/1973","Barcelona","08901"]]}
[/code]
Maybe i'm forgetting to set some option, i'm tucked with this since yesterday morning... :(
thanks again for the quick replies.
Diego.
[code]
$sEcho = $this->getRequest()->getParam("iEcho");
[/code]
asking the request for iEcho instead of sEcho, now it works like a charm.
Thanks anyway.
Diego.
It's simultaneously an annoyance and a relief when you finally find the culprit, isn't it? :-D