您好我已经在这方面工作了近2个小时了。我似乎无法找到关于jqGrid上没有显示结果的错误。我试着回应json_encode并显示出来。我的jqGrid正在我的本地网站上工作但不在现场工作。我传递一个参数,以便它不会显示其他未包含的项目。
这是我得到的:
//控制器
function all ($eid)
{
$page = isset($_POST['page'])?$_POST['page']:1;
$limit = isset($_POST['rows'])?$_POST['rows']:10;
$sidx = isset($_POST['sidx'])?$_POST['sidx']:'rank';
$sord = isset($_POST['sord'])?$_POST['sord']:'';
$start = $limit*$page - $limit;
$start = ($start<0)?0:$start;
$where = "";
$searchField = isset($_POST['searchField']) ? $_POST['searchField'] : false;
$searchOper = isset($_POST['searchOper']) ? $_POST['searchOper']: false;
$searchString = isset($_POST['searchString']) ? $_POST['searchString'] : false;
if (isset($_POST['_search']) == 'true') {
$ops = array(
'eq'=>'=',
'ne'=>'<>',
'lt'=>'<',
'le'=>'<=',
'gt'=>'>',
'ge'=>'>=',
'bw'=>'LIKE',
'bn'=>'NOT LIKE',
'in'=>'LIKE',
'ni'=>'NOT LIKE',
'ew'=>'LIKE',
'en'=>'NOT LIKE',
'cn'=>'LIKE',
'nc'=>'NOT LIKE'
);
foreach ($ops as $key=>$value){
if ($searchOper==$key) {
$ops = $value;
}
}
if($searchOper == 'eq' ) $searchString = $searchString;
if($searchOper == 'bw' || $searchOper == 'bn') $searchString .= '%';
if($searchOper == 'ew' || $searchOper == 'en' ) $searchString = '%'.$searchString;
if($searchOper == 'cn' || $searchOper == 'nc' || $searchOper == 'in' || $searchOper == 'ni') $searchString = '%'.$searchString.'%';
$where = "$searchField $ops '$searchString'";
}
if(!$sidx)
$sidx =1;
//$this->db->where('event_id', $eid);
$count = $this->db->count_all_results('table1');
if( $count > 0 ) {
$total_pages = ceil($count/$limit);
} else {
$total_pages = 0;
}
if ($page > $total_pages)
$page=$total_pages;
$query = $this->Manager_model->getcontentfromtable($start,$limit,$sidx,$sord,$where, $eid);
$responce->page = $page;
$responce->total = $total_pages;
$responce->records = $count;
$i=0;
foreach($query as $row) {
$responce->rows[$i]['rank']=$row->rank;
$pace = time_to_sec($row->runner_time)/$row->runner_cat;
$pacex = sec_to_time($pace);
$responce->rows[$i]['cell']=array($row->rank,$row->runner_name,$row->runner_cat,$row->runner_bib,$row->runner_time,$pacex);
$i++;
}
echo json_encode($responce);
}
//View
<table id="list" cellpadding="0" cellspacing="0"></table>
<div id="pager" class="scroll" style="text-align:center;"></div>
</div>
<script type="text/javascript">
$(document).ready(function (){
jQuery("#list").jqGrid({
url: '<?php echo MAINSITE_INDEX."manager/all/$eid" ?>', //another controller function for generating data
mtype : "post", //Ajax request type. It also could be GET
datatype: "json", //supported formats XML, JSON or Arrray
colNames:['Rank','Runner Name','Category','BIB','Time','Pace'], //Grid column headings
colModel :[{
name:'rank'
,index:'rank'
,width:55
},{
name:'runner_name'
,index:'runner_name'
,width:90
,editable:true
},{
name:'runner_cat'
,index:'runner_cat'
,width:80
,align:'right'
,editable:true
},{
name:'runner_bib'
,index:'runner_bib'
,width:80
,align:'rbib'
,editable:true
},{
name:'runner_time'
,index:'runner_time'
,width:80
,align:'right'
,editable:true
},{
name:'pacex'
,index:'pacex'
,width:150
,sortable:false
,editable:false
}],
rowNum:10,
width: 1050,
height: 300,
rowList:[10,20,30],
pager: '#pager',
sortname: 'rank',
viewrecords: true,
rownumbers: true,
gridview: true,
caption:"List",
viewPagerButtons: true
}).navGrid('#pager',{edit:true,add:false,del:false});
});
</script>
Model:
function getcontentfromtable($start, $limit, $sidx, $sord, $where, $eid){
$this->db->select('*');
$this->db->limit($limit);
$this->db->where('event_id', $eid);
if($where != NULL)
$this->db->where($where,NULL,FALSE);
$this->db->order_by($sidx,$sord);
$query = $this->db->get('table1',$limit,$start);
return $query->result();
}
答案 0 :(得分:0)
错误信息是什么...使用谷歌浏览器浏览您的页面并按右侧的F12或Inspect元素您可以找到错误..也请发布错误。检查您的js和css文件是否正确引用路径或不...
例如: -
&LT; script src =“../../../ Script / jquery-ui-1.7.2.custom.min.js”type =“text / javascript”&gt;
或使用Resolve URL