0

Web サービスに接続する getdocuments メソッドを使用するこの php コードがあります。 limit 、 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 {"records":20,"page":1,"total":1} で http リクエストを調べたところ、グリッドは 1 ページで 20 レコードしか表示しませんでした。20 件のレコードを表示し、ページネーションを有効にして、[次へ] を押して次の 20 件のレコードを表示できるようにしたいと考えています。これらの値を {"total":"56","page":"1","re​​cords":"560" のようにしたい

4

1 に答える 1