我已经设法使用json使jqGrid 3.8在我的项目(Zend Framework
)中工作。虽然基本的数据提取工作但我看不出为什么我看不到导航面板上显示的按钮。这是我在客户端做的事情:
<script type="text/javascript">
$(function(){
$("#roomgrid").jqGrid({
url:'/admin/admin-room/view',
datatype: "json",
autowidth: true,
colNames:['Room ID','Room Number','Room Type','Image', 'Price','Facilities'],
colModel:[ {name:'id',index:'id', width:55,editable:false,hidden:true,editoptions:{readonly:true,size:10}},
{name:'room_number',index:'room_number', width:55,editable:false,editoptions:{readonly:true,size:10}},
{name:'name',index:'name', width:80,editable:true,editoptions:{size:10}},
{name:'pic_url',index:'pic_url', width:90,editable:true,editoptions:{size:25}},
{name:'price',index:'price', width:60, align:"right",editable:true,editoptions:{size:10}},
{name:'facilities',index:'facilities', width:60, editable:true,editoptions:{size:10}}],
rowNum:5,
rowList:[5,8,10,20,30],
pager: '#paged',
sortname: 'id',
sortorder: "desc",
viewrecords: true,
caption: 'Manage Rooms'});
});
$("#roomgrid").jqGrid('navGrid','#paged', {view: true,del:true});
</script>
<table id="roomgrid"></table>
<div id="paged"></div>
在服务器端我有这个:
public function preDispatch(){
$this->_helper->viewRenderer->setNoRender();
$this->_helper->layout()->disableLayout();
}
public function viewAction() {
$filters = array(
'page'=>array('HtmlEntities','StringTrim'),
'rows'=>array('HtmlEntities','StringTrim'),
'sidx'=>array('HtmlEntities','StringTrim'),
'sord'=>array('HtmlEntities','StringTrim'));
$validators = array(
'page'=>array('NotEmpty','Int'),
'rows'=>array('NotEmpty','Int'),
'sord'=>array('NotEmpty'));
$input = new Zend_Filter_Input($filters,$validators);
$input->setData($this->getRequest()->getParams());
if($this->getRequest()){
if($input->isValid()){
$this->response->page = $input->page;
$input->rows);
echo $this->getRooms('jqgrid', $input->page, $input->rows);
}
}
}
public function getRooms($switch, $page, $rows){
$q = Doctrine_Query::create()->select("r.id,r.room_number,t.name,r.pic_url, r.price, r.facilities")
->from("Hotel_Model_Room r")
->leftJoin("r.RoomType t");
$pager = new Doctrine_Pager($q,$page, $rows);
$result = $pager->execute(array(), Doctrine_Core::HYDRATE_ARRAY);
$totalpages = $pager->getLastPage();
$totalrecord = Doctrine_Core::getTable("Hotel_Model_Room")->count();
switch ($switch){
case 'array':
return $result;
break;
case 'jqgrid' :
return $this->formatJqgridRoom($result, $page,$totalpages, $totalrecord);
break;
}
}
public function formatJqgridRoom($resultset, $page='1', $totalpages, $count){
$rows= array();
$response->page = $page;
$response->total = $totalpages;
$response->records = $count;
foreach ($resultset as $key => $value){
$response->rows[$key]['id'] = $value['id'] ;
$response->rows[$key]['cell'] = array($value['id'], $value['room_number'],$value['RoomType']['name'], $value['pic_url'], $value['price'],$value['facilities']) ;
}
return json_encode($response);
}
我正在使用jquery ui redmond主题,我确保jqGrid正在使用它,当css include被注释掉时,网格不再是蓝色。我也尝试使用imagepath
来引用css本身选项,它没有任何区别。有css文件夹结构
\css
\redmond
\images
jquery-ui-1.8.5.custom.css
ui.jqgrid.css
layout.css
另一个问题是我无法找到从哪里挑选行字体css.they在这里有点太大了。我相信我直接从jqueryui网站下载它所以我现在很少混淆。显然有些东西我我做错了,到现在为止我找不到它。所以我对此感到有些困惑。
感谢您阅读本文。
答案 0 :(得分:0)
修正了它。我忘记了我必须把寻呼机定义
$("#roomgrid").jqGrid('navGrid','#paged', {view: true,del:true});
进入查询
$(function(){})
尽可能地定义navGrid
函数。为什么它没有显示。谢谢。
我希望这有助于某人