我的第一个jqGrid实现有问题。网格正在渲染和加载数据。分页正在发挥作用。但是,网格标题显示两次。一旦作为固定标题。并且也是滚动区域的第一行。我使用MySql 5.5.11作为数据源,PHP 5.3.6,jQuery 1.6.1。和JqGrid 4.0.0。
后端网格的PHP代码如下所示:
// Processed based on the action.
switch ($lAction)
{
case "LOAD":
$page = $_POST['page']; // get the requested page
$limit = $_POST['rows']; // get how many rows we want to have into the grid
$sidx = $_POST['sidx']; // get index row - i.e. user click to sort
$sord = $_POST['sord']; // get the direction
$lDB = new DBConnection();
$lTable = "tblWebRequests";
$lGridColumns = "id,fname,lname,company,phone,email,reqfor";
$lGrid = new DBDataGrid($lDB, $lTable, $lGridColumns, 1, 5);
$response->page = $page;
$response->total = $lGrid->GetTotalPages();
$response->records = $lGrid->GetTotalItems();
$currentPageItems = $lGrid->GetCurPageItems();
for($i=0;$i<count($currentPageItems);$i++)
{
$response->rows[$i]['id']=$currentPageItems[$i]['id'];
$response->rows[$i]['cell']=array(
$currentPageItems[$i]['id'],
$currentPageItems[$i]['fname'],
$currentPageItems[$i]['lname'],
$currentPageItems[$i]['company'],
$currentPageItems[$i]['email'],
$currentPageItems[$i]['phone'],
$currentPageItems[$i]['reqfor']
);
}
echo json_encode($response);
break;
HTML如下所示:
<!-- Stylesheet includes. -->
<style type="text/css" media="screen">
@import url("css/main.css");
@import url("css/start/jquery-ui-1.8.13.custom.css");
@import url("css/ui.jqgrid.css");
</style>
<script type="text/javascript" src="js/jquery-1.6.1.min.js"></script>;
<script type="text/javascript" src="js/grid.locale-en.js"></script>;
<script type="text/javascript" src="js/jquery.jqGrid.min.js"></script>;
<div class="contentwide">
<div id="databuttons">
<p></p>
<!-- end databuttons --></div>
<div id="datasection">
<table id="datatable">
</table>
<!-- end datasection --></div>
<p></p><p></p>
<div id="datapager">
<script type="text/javascript">
$('#datatable').jqGrid({
url:'php/DataGridMgr.php',
datatype: 'json',
mtype: 'POST',
colNames:['ID','First','Last','Company','Email','Phone','Request For'],
colModel:
[
{name:'id',index:'id',width:5,editable:false,hidden:true},
{name:'fname',index:'fname', width:20,editable:false,sortable:false},
{name:'lname',index:'lname', width:20,editable:false,sortable:false},
{name:'company',index:'company', width:35,editable:false,sortable:false},
{name:'email',index:'email', width:35,editable:false,sortable:false},
{name:'phone',index:'phone', width:20,editable:false,sortable:false},
{name:'reqfor',index:'reqfor', width:25,editable:false,sortable:false}
],
rowNum:5,
rowList:[],
imgpath: 'css/start/images', //alters buttons
pager: $('#datapager'),
pginput: true,
sortname: 'id',
viewrecords: true,
sortorder: "asc",
//caption:"Pending Requests",
width:945,
height:150,
onSelectRow: function(id)
{
alert(id);
}
//editurl:""
});
</script>
<!-- end datapager --></div>
我确信我错过了一些简单的事情。我搜索无法获得解决方案。任何帮助将不胜感激。
答案 0 :(得分:0)
json响应应该有page,total,records(count),然后只有NO头的数据。在寻呼机div中有脚本我很奇怪我会把它移出来。还应将此行添加到javascript:jQuery(“#datatable”)。jqGrid('navGrid','#datapager',{edit:false,add:false,del:fal se});
另外我不使用PHP / MySQL(我使用asp.net),但看起来你正在硬编码页面值?
$ lGrid = new DBDataGrid($ lDB,$ lTable,$ lGridColumns,1,5);