Forum



05:38

26/11/2012

I have problem adding a new row of data to subgrid, however, edit and delete functions are working perfectly fine.
Whenever I add a new row of data, the data is updated in my MySQL database, but the parent table primary key did not link together, that is why the new row of data won't appear in client side.
E.g.,
Parent: Order (PK: OrderID)
Child: Hardware (PK: HardwareID)
For Order 1, there is Hardware 1.
I add new Hardware inside Order 1, by right there will be Hardware 1 and Hardware 2 appearing inside Order 1, but my problem here is Hardware 2 is not added to Order 1.
Below is my code:
order_details.php — Parent
<?php
session_start();
ob_start();
require_once 'config.php';
// include the jqGrid Class
require_once "php/jqGrid.php";
// include the PDO driver class
require_once "php/jqGridPdo.php";
// include the datepicker
require_once "php/jqCalendar.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″);// Create the jqGrid instance
$grid = new jqGridRender($conn);
// Write the SQL Query
if(isset($_SESSION['CompanyID']))
{
$CompanyID = $_SESSION['CompanyID'];
$grid->SelectCommand = "SELECT OrderID, OrderCode, Date FROM orders WHERE CompanyID='$CompanyID'";
}
else
{
$grid->SelectCommand = "SELECT OrderID, OrderCode, Date FROM orders";
}
// Set the table to where you update the data
$grid->table = 'orders';
$grid->setPrimaryKeyId("OrderID");
$grid->serialKey = false;
// set the ouput format to json
$grid->dataType = 'json';
// Let the grid create the model
$grid->setColModel();
// Set the url from where we obtain the data
$grid->setUrl('order_details.php');
// Set grid caption using the option caption
$grid->setGridOptions(array(
"rownumbers"=>true,
"caption"=>"Order List",
"rowNum"=>20,
"height"=>'auto',
"width"=>1000,
"sortname"=>"OrderID",
"hoverrows"=>true,
"rowList"=>array(10,20,50),
"subGridOptions"=>array(
"expandOnLoad"=>true
)
));
// Set the url from where we get the data
$grid->setSubGridGrid('order_subgrid.php');
// Change some property of the field(s)
$grid->setColProperty("OrderID", array("hidden"=>true));
$grid->setColProperty("OrderCode", array("label"=>"Order Code","width"=>70,"align"=>"center"));
//,"edittype"=>"textarea","formoptions"=>array("rowpos"=>4,"colpos"=>1)
$grid->setColProperty("Date", array(
"formatter"=>"date",
"formatoptions"=>array("srcformat"=>"Y-m-d H:i:s","newformat"=>"d M Y"),
"search"=>true,
"width"=>70,
"align"=>"center"
)
);
// Enable toolbar searching
$grid->toolbarfilter = true;
$grid->setFilterOptions(array("stringResult"=>true,"searchOnEnter"=>false,"defaultSearch"=>"cn"));
// Enable navigator
$grid->navigator = true;
// Enable only deleting
$grid->setNavOptions('navigator', array("excel"=>true,"add"=>true,"edit"=>true,"del"=>true,"view"=>false, "search"=>true));
// Set different filename
$grid->exportfile = 'Order.xls';
// Close the dialog after editing
$grid->setNavOptions('edit',array("closeAfterEdit"=>true,"editCaption"=>"Update Order","bSubmit"=>"Update","height"=>'auto'));
$grid->setNavOptions('add',array("addCaption"=>"Add New Order","dataheight"=>"auto"));
// Enjoy
$grid->renderGrid('#grid','#pager',true, null, null, true,true);
$conn = null;
?>
order_subgrid.php
<?php
echo "</br>";
require_once 'order_hardware.php';
echo "</br>";
require_once 'order_software.php';
echo "</br>";
require_once 'order_customisation.php';
echo "</br>";
require_once 'order_hrdf.php';
echo "</br>";
require_once 'order_ma.php';
echo "</br>";
require_once 'order_oss.php';
echo "</br>";
?>
order_hardware.php — Child
<?php
ob_start();
require_once 'config.php';
// include the jqGrid Class
require_once "php/jqGrid.php";
// include the PDO driver class
require_once "php/jqGridPdo.php";
// include the datepicker
require_once "php/jqCalendar.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″);
// Get the needed parameters passed from the main grid
// By default we add to postData subgrid and rowid parameters in the main grid
$subtable = jqGridUtils::Strip($_REQUEST["subgrid"]);
$rowid = jqGridUtils::Strip($_REQUEST["rowid"]);
$grid = new jqGridRender($conn);
// Write the SQL Query
$grid->SelectCommand = "SELECT HardwareID, OrderID, HardwareCode, HardwareName, Quantity, UnitPrice, Amount FROM hardware WHERE OrderID = ?";
// Set the table to where you update the data
$grid->table = 'hardware';
$grid->setPrimaryKeyId("HardwareID");
$grid->serialKey = false;
// set the ouput format to json
$grid->dataType = 'json';
// Let the grid create the model
$grid->setColModel(null,array(&$rowid));
// Set the url from where we obtain the data
$grid->setUrl('order_hardware.php');
// Set some grid options
$grid->setGridOptions(array(
"rownumbers"=>true,
"width"=>900,
"rowNum"=>10,
"caption"=>"Hardware",
"sortname"=>"HardwareID",
"height"=>'auto',
"expandOnLoad"=>true,
"postData"=>array("subgrid"=>$subtable,"rowid"=>$rowid)));
//the icons of the subgrid
$grid->setGridOptions(array(
"subGridOptions"=>array(
// expand all rows on load
"expandOnLoad"=>true
)
));
$grid->setSubGridGrid("hardware_serial.php");
// Change some property of the field(s)
$grid->setColProperty("HardwareID", array("hidden"=>true));
$grid->setColProperty("OrderID", array("hidden"=>true));
$grid->setColProperty("HardwareCode", array("label"=>"Hardware Code","width"=>120,"align"=>"center"));
$grid->setColProperty("HardwareName", array("label"=>"Hardware Name","width"=>300));
$grid->setColProperty("Quantity", array("width"=>70,"align"=>"center"));
$grid->setColProperty("UnitPrice", array("label"=>"Unit Price","width"=>70,"align"=>"center"));
$grid->setColProperty("Amount", array("width"=>70,"align"=>"center"));
$grid->setSelect('HardwareName', "SELECT DISTINCT HardwareName, HardwareName AS HardwareName FROM master_hardware ORDER BY HardwareName", false, true, true, array(""=>"All"));
$grid->navigator = true;
$grid->setNavOptions('navigator', array("excel"=>false,"add"=>true,"edit"=>true,"del"=>true,"view"=>false));
// Close the dialog after editing
$grid->setNavOptions('edit',array("closeAfterEdit"=>true,"editCaption"=>"Update Hardware","bSubmit"=>"Update","dataheight"=>'auto',"width"=>'auto'));
$grid->setNavOptions('add',array("addCaption"=>"Add New Hardware","dataheight"=>"auto","width"=>'auto'));
// Enjoy
$subtable = $subtable."_t";
$pager = $subtable."_p";
$grid->renderGrid($subtable,$pager, true, null, array(&$rowid), true,true);
$conn = null;
?>
Please help me have a look, I have yet to purchase a license from Trirand, and I will look forward to purchase it after this project is fully functional.
Regards,
Han
Most Users Ever Online: 715
Currently Online:
45 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