I am trying to JQGrid in Zend Framework , but not working. I am getting the Json formated string as output
Controller:
<?php
// require_once 'Zend/Controller/Action.php';
class TestController extends BaseController
{
public function indexAction()
{
// TODO Auto-generated TestController::indexAction() default action
// $this->view->pageTitle = 'Competitors';
$sidx = $this->getRequest()->getParam('sidx');
$sord = $this->getRequest()->getParam('sord');
$page = $this->getRequest()->getParam('page');
$limit = 10 ; //R $this->getRequest()->getParam('rows');
$s = new Test();
$count = $s->getNbrRace();
//$this->view->pageTitle = 'Competitors'.$count;
if( $count > 0 )
{ $total_pages = ceil($count/$limit); }
else
{ $total_pages = 0; }
if ($page > $total_pages)
$page=$total_pages;
$start = ($limit * $page)-$limit;
if ($start<0)
$start=0;
$row = $s->getListRace($sidx,$sord,$start,$limit);
$response['page'] = 1;// $page;
$response['total'] = $total_pages;
$response['records'] = $count;
$i=0;
foreach ($row as $r)
{
$response['rows'][$i]['id']=$r->r_id; //id
$response['rows'][$i]['cell']=array($r->r_id,$r->r_name,$r->r_date);
$i++;
}
//$this->_helper->json($response);
echo json_encode($response);
//echo json_encode($responce);
}
}
?>
index.phtml:
<table id="list2"></table>
<div id="pager2"></div>
<script type="text/javascript">
jQuery("#list2").jqGrid({
url:'<?php echo $this->baseUrl()?>/test/test.php',
datatype: "json",
colNames:['r_id','r_name','r_date'],
colModel:[
{name:'r_id',index:'r_id', width:55},
{name:'r_name',index:'r_name', width:90},
{name:'r_date',index:'r_date', width:100}
],
rowNum:10,
rowList:[10,20,30],
pager: '#pager2',
sortname: 'id',
viewrecords: true,
sortorder: "desc",
caption:"JSON Example"
});
jQuery("#list2").jqGrid('navGrid','#pager2',{edit:false,add:false,del:false});
</script>
Test.php:
<?php
Class Test extends BaseDbTable
{
protected $_name = 'races';
protected $_primary = 'r_id';
public function getListRace($idx,$ord,$start,$limit)
{
$select = $this->select()
->setIntegrityCheck(false)
->from(array('c' => $this->getName()) , array('r_id','r_name','r_date'));
$fetch = $this->fetchAll($select);
return $fetch;
}
public function getNbrRace()
{
$select = $this->select()
->setIntegrityCheck(false)
->from(array('c' => $this->getName()) , array('r_id'));
$fetch = $this->fetchAll($select);
return $fetch->count();
}
}
?>