PHP jqGrid Not Returning Data

760 Views Asked by At

I setup a very basic jqGrid on my Mac dev envrionment. Everything works correctly. The grid renders and the data loads no problem.

When I moved the whole site to my Windows machine, the site works fine except for the jqGrid. For some reason the grid isn't able to access the data. I'm using a PDO object to connect and query the database. The database credentials did not change when I switched from the Mac to the Windows box. I am able to use the PDO object separate from the grid, but when I pass the object to the grid, it doesn't seem to work:

<?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;

?>

I don't know what could have changed to cause this issue.

Thanks, JA

1

There are 1 best solutions below

0
On

I think you need chance $grid->setColModel(); to $grid->setColModel($vLabels);