Forum
16:35
14/06/2013
Hi,
I'm a newbie to JQGrid - I'm trying to use a separate server php page to populate the grid. The data appears to be in the grid in that I've checked the JSON message and it exports data to excel. However only the first column displays. Can someone help please?
Thanks!
David
Grid Creator PHP FILE:
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
require_once 'jq-config.php';
// include the jqGrid Class
require_once "php/jqGrid.php";
// include the PDO driver class
require_once "php/jqGridPdo.php";
// Connection to the server
// Create the jqGrid instance
$grid = new jqGridRender();
// Write the SQL Query
// set the ouput format to json
$grid->dataType = 'json';
// Let the grid create the model
$Model = array (
array ("name" => "id", "index"=>"id"),
array ("name" => "account"),
array ("name" => "s_time", "width" => 40, "align" => "right"),
array ("name" => "s_ntime"," width "=> 40," align "=>" right "),
array ("name" => "lp"," width "=> 40," align "=>" right "),
array ("name" => "cp"," width "=> 40," align "=>" right "),
array ("name" => "side"," width "=> 40," align "=>" right "),
array ("name" => "ex_price"," width "=> 40," align "=>" right "),
array ("name" => "ex_size"," width "=> 40," align "=>" right "),
array ("name" => "order_price"," width "=> 40," align "=>" right "),
array ("name" => "order_size"," width "=> 40," align "=>" right "),
);
$grid->setColModel($Model);
$grid->setUrl('server.php');
// Set grid caption using the option caption
$grid->setGridOptions(array(
"caption"=>"Orders",
"rowNum"=>30,
"sortname"=>"account",
"hoverrows"=>true,
"rowList"=>array(10,20,50),
"width"=>1500,
"height"=>100,
));
$grid->renderGrid('#grid','#pager',true, null, null, true,true);
And server file:
<?php
//include("dbconfig.php");
$page = $_REQUEST['page']; // get the requested page
$limit = $_REQUEST['rows']; // get how many rows we want to have into the grid
$sidx = $_REQUEST['sidx']; // get index row - i.e. user click to sort
$sord = $_REQUEST['sord']; // get the direction
if(!$sidx) $sidx =1;
//$page = 1;
//$limit = 10;
//$sord = "ASC";
//$sidx = "id";
// connect to the database
$database = "test1";
$db = mysql_connect("localhost:3306", "root", "") or die("Connection Error: " . mysql_error());
mysql_select_db($database) or die("Error conecting to db.");
$result = mysql_query("SELECT COUNT(*) AS count FROM TEST2");
$row = mysql_fetch_array($result,MYSQL_ASSOC);
$count = $row['count'];
if( $count >0 ) {
$total_pages = ceil($count/$limit);
} else {
$total_pages = 0;
}
if ($page > $total_pages) $page=$total_pages;
$start = $limit*$page - $limit; // do not put $limit*($page - 1)
if ($start<0) $start = 0;
$SQL = "SELECT * FROM TEST2 ORDER BY ".$sidx." ".$sord. " LIMIT ".$start." , ".$limit;
$result = mysql_query( $SQL ) or die("Could not execute query.".mysql_error());
// Construct the json data
$response = new stdClass();
$response->page = $page; // current page
$response->total = $total_pages; // total pages
$response->records = $count; // total records
$i=0;
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
$response->rows[$i]['id']=$row['id']; //id
$response->rows[$i]['cell']=array($row['id'],$row['account'],$row['s_time'],$row['s_ntime'],$row['lp'],$row['cp'],$row['side'], $row['ex_price'], $row['ex_size'], $row['order_price'], $row['order_size']);
$i++;
}
echo json_encode($response);
?>
Most Users Ever Online: 715
Currently Online:
47 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66