<?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: Master Detail not work</title>
	<link>http://www.trirand.com/blog/?page_id=393/help/master-detail-not-work</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/master-detail-not-work/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>larosal on Master Detail not work</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/master-detail-not-work#p19087</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/master-detail-not-work#p19087</guid>
        	        	<description><![CDATA[<div id="forum_ctl01_MessageList_ctl00_DisplayPost1_MessagePost1">Hi,</p>
<p>Could you help me?, I am new to jQuery and jqGrid.</p>
<p>I have a lot of time with this, my problem is: the key does not pass to the grid master to detail, in my PHP code, I will always get one empty</p>
<p>Sorry, for my English,</p>
<p>Thank a lot</p>
<p>Here is a portion of code,</p>
<p>jQuery(document).ready(function(){ <br />jQuery("#req_p").jqGrid({<br />url:&#39;solic_almac_p.php&#39;,<br />datatype:&#39;json&#39;,<br />mtype:&#39;GET&#39;,<br />colNames:[&#39;No.Requisici&#243;n&#39;,&#39;&#193;rea Solicitante&#39;,&#39;Fecha Solicitud&#39;,&#39;Cargo Solicitante&#39;],<br />colModel:[<br />{name:&#39;no_requisicion&#39;,index:&#39;no_requisicion&#39;,key:true,width:100,align:&#39;right&#39;},<br />{name:&#39;area_solicitante&#39;,index:&#39;area_solicitante&#39;,width:100,align:&#39;left&#39;},<br />{name:&#39;fec_solicitud&#39;,index:&#39;fec_solicitud&#39;,width:90,align:&#39;right&#39;},<br />{name:&#39;cargo_solicitante&#39;,index:&#39;cargo_solicitante&#39;,width:100,align:&#39;left&#39;}<br />],<br />pager:&#39;#req_p1&#39;,<br />rowNum:10,<br />rowList:[10,20,30],<br />sortname:&#39;no_requisicion&#39;,<br />sortorder:&#39;asc&#39;,<br />viewrecords:true,<br />multiselect:false,<br />caption: "SOLICITUD DE MATERIAL",<br />width:775,<br />height:&#39;auto&#39;,<br />onSelectRow: function(no_requisicion) {<br />if(no_requisicion == null) {<br />no_requisicion=0;<br />if(jQuery("#req_h1&#8243;).jqGrid(&#39;getGridParam&#39;,&#39;records&#39;) &#62;0 )<br />{<br />jQuery("#req_h1&#8243;).jqGrid(&#39;setGridParam&#39;,{url:&#39;solic_almac_h.php?id=&#39;+no_requisicion,page:1});<br />jQuery("#req_h1&#8243;).trigger("reloadGrid"); <br />}<br />} else {<br />jQuery("#req_h1&#8243;).jqGrid(&#39;setGridParam&#39;,{url:&#39;solic_almac_h.php?id=&#39;+no_requisicion,page:1});<br />jQuery("#req_h1&#8243;).trigger("reloadGrid"); <br />}<br />}<br />});<br />jQuery("#req_p").jqGrid(&#39;navGrid&#39;,&#39;#req_p1&#39;,{add:true,edit:true,del:true});</p>
<p>jQuery("#req_h").jqGrid({<br />url:&#39;solic_almac_h.php&#39;,<br />datatype: "json",<br />colNames:[&#39;No.&#39;,&#39;Desc.Art&#237;culo&#39;, &#39;U.Medida&#39;,&#39;Solic.&#39;,&#39;$ Unitario&#39;,&#39;$ Total&#39;],<br />colModel:[<br />{name:&#39;no_prog&#39;,index:&#39;no_prog&#39;, width:40, align:&#39;right&#39;,resizable:false,editable:false,editoptions:{readonly:true,size:10}},<br />{name:&#39;articulo&#39;,index:&#39;articulo&#39;, width:300, align:&#39;left&#39;,editable:true,editoptions:{size:25}},<br />{name:&#39;unidad_medida&#39;,index:&#39;unidad_medida&#39;, width:100, align:&#39;left&#39;,resizable:false,editable:true,editoptions:{size:10}},<br />{name:&#39;solicitado&#39;,index:&#39;solicitado&#39;, width:60, align:&#39;right&#39;,resizable:false,editable:true,editoptions:{size:10}}, <br />{name:&#39;costo_unitario&#39;,index:&#39;costo_unitario&#39;,width:90, align:&#39;right&#39;,resizable:false,editable:false},<br />{name:&#39;costo_total&#39;,index:&#39;costo_total&#39;,width:100, align:&#39;right&#39;, editable:false},<br />],<br />rowNum:5,<br />rowList:[5,10,20],<br />pager:&#39;#req_h1&#39;,<br />sortname:&#39;no_prog&#39;,<br />viewrecords:true,<br />sortorder:&#39;asc&#39;,<br />caption:&#39;Detalle&#39;,<br />height:&#39;auto&#39;<br />});<br />jQuery("#req_h").jqGrid(&#39;navGrid&#39;,&#39;#req_h1&#39;,<br />{}, //options<br />{height:280,reloadAfterSubmit:false}, // edit options<br />{height:280,reloadAfterSubmit:false}, // add options<br />{reloadAfterSubmit:false}, // del options<br />{} // search options<br />);<br />})</p>
</div>
<div>Here is the master PHP code, </p>
<p><strong><em>&#60;?php <br />include_once ("conexion.php"); </em></strong></p>
<p>// to the url parameter are added 4 parameters as described in colModel<br />// we should get these parameters to construct the needed query<br />// Since we specify in the options of the grid that we will use a GET method <br />// we should use the appropriate command to obtain the parameters. <br />// In our case this is $_GET. If we specify that we want to use post <br />// we should use $_POST. Maybe the better way is to use $_REQUEST, which<br />// contain both the GET and POST variables. For more information refer to php documentation.<br />// Get the requested page. By default grid sets this to 1. <br />include("php/JSON.php");</p>
<p>$json = new Services_JSON();</p>
<p>$page = $_GET[&#39;page&#39;]; </p>
<p>// get how many rows we want to have into the grid - rowNum parameter in the grid <br />$limit = $_GET[&#39;rows&#39;]; </p>
<p>// get index row - i.e. user click to sort. At first time sortname parameter -<br />// after that the index from colModel <br />$sidx = $_GET[&#39;sidx&#39;]; </p>
<p>// sorting order - at first time sortorder <br />$sord = $_GET[&#39;sord&#39;]; </p>
<p>// if we not pass at first time index use the first column for the index or what you want<br />if(!$sidx) $sidx =1; </p>
<p>// connect to the MySQL database server and the database, too<br />$Conexion=new Conexion();<br />$Conexion-&#62;getConexion();</p>
<p>// calculate the number of rows for the query. We need this to paging the result<br />$result = mysql_query("SELECT COUNT(*) AS count FROM requisicion_p");<br />$row = mysql_fetch_array($result,MYSQL_ASSOC);<br />$count = $row[&#39;count&#39;];</p>
<p>// calculate the total pages for the query <br />if( $count &#62; 0 &#38;&#38; $limit &#62; 0) { <br />$total_pages = ceil($count/$limit); <br />} else { <br />$total_pages = 0; <br />} </p>
<p>// if for some reasons the requested page is greater than the total <br />// set the requested page to total page <br />if ($page &#62; $total_pages) $page=$total_pages;</p>
<p>// calculate the starting position of the rows <br />$start = $limit*$page - $limit;</p>
<p>// if for some reasons start position is negative set it to 0 <br />// typical case is that the user type 0 for the requested page <br />if($start &#60;0) $start = 0; </p>
<p>// the actual query for the grid data<br />$query="SELECT no_requisicion,";<br />$query.="desc_area_solicitante as area_solicitante,";<br />$query.="DATE_FORMAT(fec_solicitud,&#39;%d/%m/%Y&#39;) as fec_solicitud,";<br />$query.="desc_cargo_solicitante as cargo_solicitante ";<br />$query.="FROM requisicion_p,area_solicitante,cargo_solicitante ";<br />$query.="WHERE no_area_solicitante=area_solicitante ";<br />$query.="AND no_cargo_solicitante=cargo_solicitante ";<br />$query.="ORDER BY $sidx $sord LIMIT $start,$limit";<br />$result = mysql_query( $query ) or die("No se puede ejecutar la sentencia.".mysql_error());</p>
<p>// constructing a JSON<br />$response-&#62;page = $page;<br />$response-&#62;total = $total_pages;<br />$response-&#62;records = $count;<br />$i=0;<br />while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {<br />$response-&#62;rows[$i][&#39;no_requisicion&#39;]=$row[no_requisicion];<br />$response-&#62;rows[$i][&#39;cell&#39;]=array($row[no_requisicion],$row[area_solicitante],$row[fec_solicitud],$row[cargo_solicitante]);<br />$i++;<br />}</p>
<p>//Cierra la conexi&#243;n<br />$Conexion-&#62;Close(); </p>
<p>// return the formated data<br />echo $json-&#62;encode($response);<br />?&#62;</p>
<p>This is Detail PHP code,</p>
<p><strong><em>&#60;?php <br />include_once ("conexion.php"); </em></strong></p>
<p>// to the url parameter are added 4 parameters as described in colModel<br />// we should get these parameters to construct the needed query<br />// Since we specify in the options of the grid that we will use a GET method <br />// we should use the appropriate command to obtain the parameters. <br />// In our case this is $_GET. If we specify that we want to use post <br />// we should use $_POST. Maybe the better way is to use $_REQUEST, which<br />// contain both the GET and POST variables. For more information refer to php documentation.<br />// Get the requested page. By default grid sets this to 1. <br />include("php/JSON.php");</p>
<p>$json = new Services_JSON();</p>
<p>$page = $_GET[&#39;page&#39;]; </p>
<p>// get how many rows we want to have into the grid - rowNum parameter in the grid <br />$limit = $_GET[&#39;rows&#39;]; </p>
<p>// get index row - i.e. user click to sort. At first time sortname parameter -<br />// after that the index from colModel <br />$sidx = $_GET[&#39;sidx&#39;]; </p>
<p>// sorting order - at first time sortorder <br />$sord = $_GET[&#39;sord&#39;]; </p>
<p>// if we not pass at first time index use the first column for the index or what you want<br />if(!$sidx) $sidx =1; </p>
<p>//Conexi&#243;n a MySQL y a la BD<br />$Conexion=new Conexion();<br />$Conexion-&#62;getConexion();</p>
<p>// calculate the number of rows for the query. We need this to paging the result<br />$no_requisicion = (isset($_REQUEST[&#39;id&#39;]) ? trim($_REQUEST[&#39;id&#39;] ): null);<br />if ($no_requisicion!=null){<br />$result = mysql_query("SELECT COUNT(*) AS count FROM requisicion_h WHERE no_requisicion = $no_requisicion");<br />}<br />else{<br />$result = mysql_query("SELECT COUNT(*) AS count FROM requisicion_h");<br />}<br />$row = mysql_fetch_array($result,MYSQL_ASSOC);<br />$count = $row[&#39;count&#39;];</p>
<p>// calculate the total pages for the query <br />if( $count &#62; 0 &#38;&#38; $limit &#62; 0) { <br />$total_pages = ceil($count/$limit); <br />} else { <br />$total_pages = 0; <br />} </p>
<p>// if for some reasons the requested page is greater than the total <br />// set the requested page to total page <br />if ($page &#62; $total_pages) $page=$total_pages;</p>
<p>// calculate the starting position of the rows <br />$start = $limit*$page - $limit; // do not put $limit*($page - 1)</p>
<p>// if for some reasons start position is negative set it to 0 <br />// typical case is that the user type 0 for the requested page <br />if ($start&#60;0) $start = 0;</p>
<p>// the actual query for the grid data<br />$query="SELECT no_prog,desc_articulo as articulo,desc_unidad_medida as unidad_medida,solicitado,precio as costo_unitario, ";<br />$query.="solicitado*precio as costo_total ";<br />$query.="FROM requisicion_h,articulos,unidad_medida ";<br />$query.="WHERE articulo=no_articulo ";<br />$query.="AND unidad_medida=no_unidad_medida ";</p>
<p>if ($no_requisicion!=null){<br />$query.="AND no_requisicion=$no_requisicion ";<br />}<br />$query.="ORDER BY $sidx $sord LIMIT $start, $limit";<br />$result = mysql_query($query) or die("No se puede ejecutar la sentencia.".mysql_error());</p>
<p>// constructing a JSON<br />$response-&#62;page = $page;<br />$response-&#62;total = $total_pages;<br />$response-&#62;records = $count;<br />$i=0;<br />while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {<br />$response-&#62;rows[$i][&#39;no_prog&#39;]=$row[no_prog];<br />$response-&#62;rows[$i][&#39;cell&#39;]=array($row[no_prog],$row[articulo],$row[unidad_medida],$row[solicitado],$row[costo_unitario],$row[costo_total]);<br />$i++;<br />}</p>
<p>//Cierra la conexi&#243;n<br />$Conexion-&#62;Close();</p>
<p>// return the formated data<br />echo $json-&#62;encode($response); <br />?&#62;</p>
<p>Thanks a lot</p>
</div>
]]></description>
        	        	<pubDate>Wed, 11 Aug 2010 19:28:36 +0300</pubDate>
        </item>
</channel>
</rss>