我在Mac开发环境中设置了一个非常基本的jqGrid。一切正常。网格呈现并且数据加载没有问题。
当我将整个站点移动到我的Windows机器时,除了jqGrid之外,该站点工作正常。由于某种原因,网格无法访问数据。我正在使用PDO对象来连接和查询数据库。当我从Mac切换到Windows框时,数据库凭据没有改变。我可以使用与网格分开的PDO对象,但是当我将对象传递给网格时,它似乎不起作用:
<?php
require_once '../Grid/jq-config.php';
// include the jqGrid Class
require_once "../Grid/php/jqGrid.php";
// include the PDO driver class
require_once "../Grid/php/jqGridPdo.php";
// Connection to the server
$conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD);
// Tell the db that we use utf-8
//$conn->query("SET NAMES utf8");
$selectCommand = "SELECT VolunteerID, FirstName, LastName, PhoneNumber, Email FROM Volunteers";
// Definition of the labels
$vLabels = array("VolunteerID"=>"Id",
"FirstName" => "First Name",
"LastName" => "Last Name",
"PhoneNumber" => "Phone Number",
"Email" => "Email");
// Create the jqGrid instance
$grid = new jqGridRender($conn);
// Write the SQL Query
$grid->SelectCommand = $selectCommand;
// set the ouput format to json
$grid->dataType = "json";
// Let the grid create the model
//$grid->setColModel(null, null, $vLabels);
$grid->setColModel();
// Set the url from where we obtain the data
$grid->setUrl('VolunteerListGrid.php');
// Set grid caption using the option caption
$grid->setGridOptions(array(
"caption"=>"Volunteers",
"rowNum"=>10,
"sortname"=>"VolunteerID",
"hoverrows"=>true,
"rowList"=>array(10,20,50)
));
// Enjoy
$grid->renderGrid('#grid','#pager',true, null, null, true, true);
//$test = $conn->query($selectCommand);
//$data = $test->fetchAll(PDO::FETCH_ASSOC);
//
//echo json_encode($data);
$conn = null;
?>
我不知道可能导致此问题的原因。
谢谢, JA
答案 0 :(得分:0)
我认为你需要机会$grid->setColModel();
到$grid->setColModel($vLabels);