<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
	<title>jQuery Grid Plugin - jqGrid - Topic: Add data to subgrid not working</title>
	<link>http://www.trirand.com/blog/?page_id=393/help/add-data-to-subgrid-not-working</link>
	<description><![CDATA[Grid plugin]]></description>
	<generator>Simple:Press Version 5.7.5.3</generator>
	<atom:link href="http://www.trirand.com/blog/?page_id=393/help/add-data-to-subgrid-not-working/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>hanstt on Add data to subgrid not working</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/add-data-to-subgrid-not-working#p27786</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/add-data-to-subgrid-not-working#p27786</guid>
        	        	<description><![CDATA[<p>I have problem adding a new row of data to subgrid, however, edit and delete functions are working perfectly fine.</p>
<p>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&#39;t appear in client side.</p>
<p>E.g.,</p>
<p>Parent: Order (PK: OrderID)</p>
<p>Child: Hardware (PK: HardwareID)</p>
<p>For Order 1, there is Hardware 1.</p>
<p>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.</p>
<p>Below is my code:</p>
<p>order_details.php &#8212; Parent</p>
</p>
<blockquote>
<p>&#60;?php<br />session_start();<br />ob_start();<br />require_once &#39;config.php&#39;;<br />// include the jqGrid Class<br />require_once "php/jqGrid.php";<br />// include the PDO driver class<br />require_once "php/jqGridPdo.php";<br />// include the datepicker<br />require_once "php/jqCalendar.php"; <br />// Connection to the server<br />$conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD);<br />// Tell the db that we use utf-8<br />$conn-&#62;query("SET NAMES utf8&#8243;);</p>
<p>// Create the jqGrid instance<br />$grid = new jqGridRender($conn);<br />// Write the SQL Query&#160;&#160; &#160;<br />if(isset($_SESSION[&#39;CompanyID&#39;]))<br />{<br />$CompanyID = $_SESSION[&#39;CompanyID&#39;];<br />$grid-&#62;SelectCommand = "SELECT OrderID, OrderCode, Date FROM orders WHERE CompanyID=&#39;$CompanyID&#39;"; <br />}<br />else<br />{<br />$grid-&#62;SelectCommand = "SELECT OrderID, OrderCode, Date FROM orders"; <br />}<br />// Set the table to where you update the data<br />$grid-&#62;table = &#39;orders&#39;; <br />$grid-&#62;setPrimaryKeyId("OrderID");<br />$grid-&#62;serialKey = false; <br />// set the ouput format to json<br />$grid-&#62;dataType = &#39;json&#39;;<br />// Let the grid create the model<br />$grid-&#62;setColModel();<br />// Set the url from where we obtain the data<br />$grid-&#62;setUrl(&#39;order_details.php&#39;);<br />// Set grid caption using the option caption<br />$grid-&#62;setGridOptions(array(<br />&#160;&#160; &#160;"rownumbers"=&#62;true,<br />&#160;&#160;&#160; "caption"=&#62;"Order List",<br />&#160;&#160;&#160; "rowNum"=&#62;20,<br />&#160;&#160; &#160;"height"=&#62;&#39;auto&#39;, <br />&#160;&#160; &#160;"width"=&#62;1000,<br />&#160;&#160;&#160; "sortname"=&#62;"OrderID",<br />&#160;&#160;&#160; "hoverrows"=&#62;true,<br />&#160;&#160;&#160; "rowList"=&#62;array(10,20,50),<br />&#160;&#160; &#160;"subGridOptions"=&#62;array(<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; "expandOnLoad"=&#62;true<br />&#160;&#160;&#160; ) <br />));<br />// Set the url from where we get the data<br />$grid-&#62;setSubGridGrid(&#39;order_subgrid.php&#39;); <br />// Change some property of the field(s)<br />$grid-&#62;setColProperty("OrderID", array("hidden"=&#62;true));<br />$grid-&#62;setColProperty("OrderCode", array("label"=&#62;"Order Code","width"=&#62;70,"align"=&#62;"center"));<br />//,"edittype"=&#62;"textarea","formoptions"=&#62;array("rowpos"=&#62;4,"colpos"=&#62;1)<br />$grid-&#62;setColProperty("Date", array(<br />&#160;&#160;&#160; "formatter"=&#62;"date",<br />&#160;&#160;&#160; "formatoptions"=&#62;array("srcformat"=&#62;"Y-m-d H:i:s","newformat"=&#62;"d M Y"),<br />&#160;&#160; &#160;"search"=&#62;true,<br />&#160;&#160; &#160;"width"=&#62;70,<br />&#160;&#160; &#160;"align"=&#62;"center" <br />&#160;&#160;&#160; )<br />);<br />// Enable toolbar searching<br />$grid-&#62;toolbarfilter = true;<br />$grid-&#62;setFilterOptions(array("stringResult"=&#62;true,"searchOnEnter"=&#62;false,"defaultSearch"=&#62;"cn")); <br />// Enable navigator<br />$grid-&#62;navigator = true;<br />// Enable only deleting<br />$grid-&#62;setNavOptions(&#39;navigator&#39;,   array("excel"=&#62;true,"add"=&#62;true,"edit"=&#62;true,"del"=&#62;true,"view"=&#62;false,  "search"=&#62;true));<br />// Set different filename<br />$grid-&#62;exportfile = &#39;Order.xls&#39;; <br />// Close the dialog after editing<br />$grid-&#62;setNavOptions(&#39;edit&#39;,array("closeAfterEdit"=&#62;true,"editCaption"=&#62;"Update  Order","bSubmit"=&#62;"Update","height"=&#62;&#39;auto&#39;)); <br />$grid-&#62;setNavOptions(&#39;add&#39;,array("addCaption"=&#62;"Add New Order","dataheight"=&#62;"auto")); <br />// Enjoy<br />$grid-&#62;renderGrid(&#39;#grid&#39;,&#39;#pager&#39;,true, null, null, true,true);<br />$conn = null;<br />?&#62;</p>
</blockquote>
<p>order_subgrid.php</p>
<blockquote>
<p>&#60;?php<br />echo "&#60;/br&#62;";<br />require_once &#39;order_hardware.php&#39;;<br />echo "&#60;/br&#62;";<br />require_once &#39;order_software.php&#39;;<br />echo "&#60;/br&#62;";<br />require_once &#39;order_customisation.php&#39;;<br />echo "&#60;/br&#62;";<br />require_once &#39;order_hrdf.php&#39;;<br />echo "&#60;/br&#62;";<br />require_once &#39;order_ma.php&#39;;<br />echo "&#60;/br&#62;";<br />require_once &#39;order_oss.php&#39;;<br />echo "&#60;/br&#62;";<br />?&#62;</p>
</blockquote>
<p>order_hardware.php &#8212; Child</p>
<blockquote>
<p>&#60;?php<br />ob_start();<br />require_once &#39;config.php&#39;;<br />// include the jqGrid Class<br />require_once "php/jqGrid.php";<br />// include the PDO driver class<br />require_once "php/jqGridPdo.php";<br />// include the datepicker<br />require_once "php/jqCalendar.php"; <br />// Connection to the server<br />$conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD);<br />// Tell the db that we use utf-8<br />$conn-&#62;query("SET NAMES utf8&#8243;);<br />// Get the needed parameters passed from the main grid<br />// By default we add to postData subgrid and rowid parameters in the main grid<br />$subtable = jqGridUtils::Strip($_REQUEST["subgrid"]);<br />$rowid = jqGridUtils::Strip($_REQUEST["rowid"]);<br />$grid = new jqGridRender($conn);<br />// Write the SQL Query<br />$grid-&#62;SelectCommand = "SELECT HardwareID, OrderID, HardwareCode, HardwareName, Quantity, UnitPrice, Amount FROM hardware WHERE OrderID = ?";<br />// Set the table to where you update the data<br />$grid-&#62;table = &#39;hardware&#39;; <br />$grid-&#62;setPrimaryKeyId("HardwareID");<br />$grid-&#62;serialKey = false; <br />// set the ouput format to json<br />$grid-&#62;dataType = &#39;json&#39;;<br />// Let the grid create the model<br />$grid-&#62;setColModel(null,array(&#38;$rowid));<br />// Set the url from where we obtain the data<br />$grid-&#62;setUrl(&#39;order_hardware.php&#39;);<br />// Set some grid options<br />$grid-&#62;setGridOptions(array(<br />&#160;&#160; &#160;"rownumbers"=&#62;true,<br />&#160;&#160;&#160; "width"=&#62;900,<br />&#160;&#160;&#160; "rowNum"=&#62;10,<br />&#160;&#160; &#160;"caption"=&#62;"Hardware",<br />&#160;&#160;&#160; "sortname"=&#62;"HardwareID",<br />&#160;&#160;&#160; "height"=&#62;&#39;auto&#39;,<br />&#160;&#160; &#160;"expandOnLoad"=&#62;true, <br />&#160;&#160;&#160; "postData"=&#62;array("subgrid"=&#62;$subtable,"rowid"=&#62;$rowid)));<br />//the icons of the subgrid<br />$grid-&#62;setGridOptions(array(<br />&#160;&#160;&#160; "subGridOptions"=&#62;array(<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; // expand all rows on load<br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; "expandOnLoad"=&#62;true<br />&#160;&#160;&#160; )<br />));<br />$grid-&#62;setSubGridGrid("hardware_serial.php"); <br />// Change some property of the field(s)<br />$grid-&#62;setColProperty("HardwareID", array("hidden"=&#62;true));<br />$grid-&#62;setColProperty("OrderID", array("hidden"=&#62;true));<br />$grid-&#62;setColProperty("HardwareCode", array("label"=&#62;"Hardware Code","width"=&#62;120,"align"=&#62;"center"));<br />$grid-&#62;setColProperty("HardwareName", array("label"=&#62;"Hardware Name","width"=&#62;300));<br />$grid-&#62;setColProperty("Quantity", array("width"=&#62;70,"align"=&#62;"center"));<br />$grid-&#62;setColProperty("UnitPrice", array("label"=&#62;"Unit Price","width"=&#62;70,"align"=&#62;"center"));<br />$grid-&#62;setColProperty("Amount", array("width"=&#62;70,"align"=&#62;"center"));<br />$grid-&#62;setSelect(&#39;HardwareName&#39;, "SELECT DISTINCT HardwareName, HardwareName AS HardwareName FROM master_hardware ORDER BY HardwareName", false, true, true, array(""=&#62;"All")); <br />$grid-&#62;navigator = true;<br />$grid-&#62;setNavOptions(&#39;navigator&#39;, array("excel"=&#62;false,"add"=&#62;true,"edit"=&#62;true,"del"=&#62;true,"view"=&#62;false));<br />// Close the dialog after editing<br />$grid-&#62;setNavOptions(&#39;edit&#39;,array("closeAfterEdit"=&#62;true,"editCaption"=&#62;"Update Hardware","bSubmit"=&#62;"Update","dataheight"=&#62;&#39;auto&#39;,"width"=&#62;&#39;auto&#39;)); <br />$grid-&#62;setNavOptions(&#39;add&#39;,array("addCaption"=&#62;"Add New Hardware","dataheight"=&#62;"auto","width"=&#62;&#39;auto&#39;)); <br />// Enjoy<br />$subtable = $subtable."_t";<br />$pager = $subtable."_p";<br />$grid-&#62;renderGrid($subtable,$pager, true, null, array(&#38;$rowid), true,true);<br />$conn = null;<br />?&#62;</p>
</blockquote>
<p>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.</p>
<p>Regards,</p>
<p>Han</p></p>
]]></description>
        	        	<pubDate>Mon, 26 Nov 2012 05:38:06 +0200</pubDate>
        </item>
</channel>
</rss>