我有这个PHP代码,我使用getdocuments方法连接到Web服务,我传递限制,pageNumber和可选的过滤器数组,它返回一个数据数组,除了记录和页码的总数
我想在jqgrid中显示结果,我想提供20个记录,当用户进入下一页时,请带下接下来的20条记录。
<?php
//ini_set("display_errors","1");
require_once 'grid/jq-config.php';
// include the jqGrid Class
require_once "grid/jqGrid.php";
// include the driver class
require_once "grid/jqGridArray.php";
// include the calendar
require_once "grid/jqCalendar.php";
// include the document class
require_once "lib/document.php";
// include heler.php which contain some helper functions
require_once "lib/helper.php";
// create the array connection
$conn = new jqGridArray();
// Create the jqGrid instance
$grid = new jqGridRender($conn);
// prepare array that contains fileds name which user can filter on
$fields = array("BatchNumber", "SenderCode","ReceiverCode","DocumentNumber","DocumentType","InResponse","SubmitDate");
if(get_magic_quotes_gpc()){
$d = stripslashes($_REQUEST["filters"]);
}else{
$d = $_REQUEST["filters"];
}
$d = json_decode($d);
for($i = 0; $i < count($d->rules); $i++){
foreach ($fields as $value) {
if($d->rules[$i]->field == $value){
$option[$value] == $d->rules[$i]->data;
}
}
}
if(isset($_GET["page"])){
$option["PageNumber"] = $_GET["page"];
}
else{
$option["PageNumber"] = 1;
}
if(isset($_GET["rows"])){
$option["Limit"] = $_GET["rows"];
}
else{
$option["Limit"] = LIMIT_DOCUMENT;
}
$results = Document::getDocuments($option);
$arrResult = _object_to_array($results);
$documents = $arrResult["Documents"]["DocumentDataModel"];
$totalCount = $arrResult["TotalCount"] ;
$totalPages = ceil($totalCount/ $option["Limit"]);
// Always you can use SELECT * FROM data1
$grid->SelectCommand = "SELECT BatchNumber, SenderCode ,ReceiverCode , DocumentNumber, DocumentType, InResponse, SubmitDate,LastModifiedDate FROM documents";
$grid->dataType = 'json';
$grid->setPrimaryKeyId('BatchNumber');
$grid->setColModel();
//enable subgrid
// Set the parameters for the subgrid
$grid->setSubGrid("subgrid_document_attachments.php",
array('File Name'),
array(60),
array('left'));
// Enable toolbar searching
$grid->toolbarfilter = true;
$grid->setFilterOptions(array("stringResult"=>TRUE));
$grid->setUrl('grid_documents.php');
$grid->setGridOptions(array(
"width" => 1124,
"height" => 400,
"rowList"=>array(10,20,30,40,50,100),
"sortname"=>"id",
"caption" => "Documents",
"total" => $arrResult["TotalPages"],
"records" => $arrResult['TotalCount'],
"page" => $arrResult['PageNumber'],
));
$grid->setColProperty("BatchNumber", array("label"=>"Batch Number"));
$grid->setColProperty("SubmitDate", array(
"formatter"=>"date",
"formatoptions"=>array("srcformat"=>"Y-m-d H:i:s","newformat"=>"m/d/Y")
)
);
// format the last modified date
$grid->setColProperty("LastModifiedDate", array(
"formatter"=>"date",
"formatoptions"=>array("srcformat"=>"Y-m-d H:i:s","newformat"=>"m/d/Y")
)
);
// add date picker to submit date
$grid->setDatepicker("SubmitDate",array("buttonOnly"=>FALSE));
$grid->datearray = array('SubmitDate');
// Enable navigator
$grid->navigator = true;
// Enable search
$grid->setNavOptions('navigator', array("excel"=>TRUE,"add"=>false,"edit"=>false,"del"=>false,"view"=>false,"csv"=>FALSE, "pdf"=>false));
// Activate single search
$grid->setNavOptions('search',array("multipleSearch"=>false));
// Enjoy
$grid->renderGrid('#grid','#pager',true, null, null, true,true);
?>
我通过firebug检查了http请求,{“records”:20,“page”:1,“total”:1},网格只显示20条记录和1页。我希望它显示20条记录并启用分页,这样我就可以按下一条并带下接下来的20条记录。我希望这些值类似于{“total”:“56”,“page”:“1”,“records”:“560”
答案 0 :(得分:0)
jqGrid会将所有信息传递给您需要检索需要显示的正确数据页面的Web服务。排序索引(sidx),排序顺序(sord),页面(页面)和行(行)。
您的控制器/网络服务可以获取此信息,然后从您的数据集中获取相应的数据。
public ActionResult getGridData(string sidx, string sord, int page, int rows, bool _search, string filters) {
...
var pagedDataset = fullDataset.OrderBy(sidx + " " + sord).Skip((page - 1) * rows).Take(rows);
//then format the pagedDataset for the jqGrid and pass it back.