<?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: jqgrid cascading dropdown</title>
	<link>http://www.trirand.com/blog/?page_id=393/help/jqgrid-cascading-dropdown</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/jqgrid-cascading-dropdown/rss" rel="self" type="application/rss+xml" />
        <item>
        	<title>leerickx on jqgrid cascading dropdown</title>
        	<link>http://www.trirand.com/blog/?page_id=393/help/jqgrid-cascading-dropdown#p28301</link>
        	<category>Help</category>
        	<guid isPermaLink="true">http://www.trirand.com/blog/?page_id=393/help/jqgrid-cascading-dropdown#p28301</guid>
        	        	<description><![CDATA[<p><span style="font-size: 14px;">Hello everybody&#8230; i&#39;m lost&#160;&#160;,</span></p>
<p>I try to realize cascading dropdown. My data is in tables.</p>
<p>If i choose an item in the first ddl the second ddl change right.</p>
<p>But the first time that i want edit or add my second ddl present all items from the table (ddlprojet &#8211; table :projet).</p>
<p>How I can do change this ? Thanks for all.</p>
<p>My html code:</p>
<p>&#60;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&#62;</p>
<p>&#60;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&#62;</p>
<p>&#60;head&#62;</p>
<p>&#60;meta http-equiv="Content-Type" content="text/html; charset=utf-8&#8243; /&#62;</p>
<p>&#60;title&#62;My First Grid&#60;/title&#62;</p>
</p>
<p>&#60;link rel="stylesheet" type="text/css" media="screen" href="css/redmond/jquery-ui-1.10.0.custom.min.css" /&#62;</p>
<p>&#60;link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" /&#62;</p>
</p>
<p>&#60;style&#62;</p>
<p>html, body {</p>
<p>&#160;&#160;&#160; margin: 0;</p>
<p>&#160;&#160;&#160; padding: 0;</p>
<p>&#160;&#160;&#160; font-size: 75%;</p>
<p>}</p>
<p>&#60;/style&#62;</p>
</p>
<p>&#60;script src="js/jquery-1.9.0.min.js" type="text/javascript"&#62;&#60;/script&#62;</p>
<p>&#60;script src="js/i18n/grid.locale-fr.js" type="text/javascript"&#62;&#60;/script&#62;</p>
<p>&#60;script src="js/jquery.jqGrid.min.js" type="text/javascript"&#62;&#60;/script&#62;</p>
</p>
<p>&#60;script&#62;</p>
<p>$(function(){</p>
</p>
<p>&#160; $("#list").jqGrid({</p>
<p>&#160;&#160;&#160; //=============</p>
<p>&#160;&#160;&#160; // Grid Setup</p>
<p>&#160;&#160;&#160; url:&#39;example.php&#39;,</p>
<p>&#160;&#160;&#160; datatype: &#39;xml&#39;,</p>
<p>&#160;&#160;&#160; mtype: &#39;GET&#39;,</p>
<p>&#160;&#160;&#160; pager: &#39;#gridpager&#39;,</p>
<p>&#160;&#160;&#160; width: 700,</p>
<p>&#160;&#160;&#160; height: &#39;130%&#39;,</p>
<p>&#160;&#160;&#160; rowNum:10,</p>
<p>&#160;&#160;&#160; rowList:[10,20,30],</p>
<p>&#160;&#160;&#160; sortname: &#39;secteur&#39;,</p>
<p>&#160;&#160;&#160; sortorder: &#39;desc&#39;,</p>
<p>&#160;&#160;&#160; viewrecords: true,</p>
<p>&#160;&#160;&#160; gridview: true,</p>
<p>&#160;&#160;&#160; editurl: "addupdatedeldata.php",</p>
<p>&#160;&#160;&#160; onSelectRow: function(rowid) {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (rowid != null) {</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; var record = $("#list").getRowData(rowid);</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#160;&#160;&#160;var pgm="ddlprojet.php?id_secteur="+record.idsecteur;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; $("#list").setColProp(&#39;select#idprojet&#39;,{editoptions:{dataUrl:pgm}});</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; },</p>
<p>&#160;&#160;&#160; caption: &#39;FICHE PROJET&#39;,</p>
</p>
<p>&#160;&#160;&#160; // Column definition</p>
<p>&#160;&#160;&#160; colNames:[&#39;id&#39;,&#39;date&#39;, &#39;secteur&#39;,&#39;projet&#39;],</p>
<p>&#160;&#160;&#160; colModel :[</p>
<p>&#160;&#160;&#160;&#160;&#160; {name:&#39;id&#39;, index:&#39;id&#39;, width:55},</p>
<p>&#160;&#160;&#160;&#160;&#160; {name:&#39;date&#39;, index:&#39;date&#39;, width:90, editable:true},</p>
<p>&#160;&#160;&#160;&#160;&#160; {name:&#39;idsecteur&#39;, index:&#39;idsecteur&#39;, width:80, align:&#39;right&#39;, editable:true, edittype:"select",&#160;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; editoptions:{dataUrl:&#39;ddlsecteur.php&#39;, dataEvents:[{type: &#39;change&#39;,</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; fn: function(e) {var thisval = $(e.target).val();</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;$.get(&#39;ddlprojet.php?id_secteur=&#39;+thisval,</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; function(data)</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; { $("select#idprojet").html(data);</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }); // end get</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }//end func</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; } // end type</p>
<p>&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;] // dataevents</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; } // edit option</p>
<p>&#160;&#160;&#160; },</p>
</p>
<p>&#160;&#160;&#160;&#160;&#160; {name:&#39;idprojet&#39;, index:&#39;idprojet&#39;, width:80, align:&#39;right&#39;, editable:true, edittype:"select", editoptions:{dataUrl:&#39;ddlprojet.php?id_secteur=idsecteur&#39;}}</p>
<p>&#160;&#160;&#160; ]</p>
<p>&#160;&#160;&#160;&#160;&#160; });</p>
</p>
<p>&#160;&#160;&#160; //=============</p>
<p>&#160;&#160;&#160; // NavGrid Setup</p>
</p>
<p>&#160;&#160;&#160; $("#list").jqGrid(&#39;navGrid&#39;,&#39;#gridpager&#39;,</p>
<p>&#160;&#160;&#160; {edit:true,</p>
<p>&#160;&#160;&#160; add:true,</p>
<p>&#160;&#160;&#160; del:true,</p>
<p>&#160;&#160;&#160; search:true},&#160;&#160;</p>
<p>&#160;&#160;&#160; {viewPagerButtons:false,</p>
<p>&#160;&#160;&#160; recreateForm:true</p>
<p>&#160;&#160;&#160; //refresh:true</p>
<p>&#160;&#160;&#160; });</p>
</p>
<p>});</p>
</p>
<p>&#60;/script&#62;</p>
</p>
<p>&#60;/head&#62;</p>
<p>&#60;body&#62;</p>
<p>&#60;table id="list"&#62;&#60;tr&#62;&#60;td/&#62;&#60;/tr&#62;&#60;/table&#62;</p>
<p>&#60;div&#62;&#60;/div&#62;</p>
<p>&#60;/body&#62;</p>
<p>&#60;/html&#62;</p>
<p>my ddlsecteur.php</p>
<p>&#60;?php</p>
<p>&#160;&#160;&#160; include("dbconfig.php");</p>
</p>
<p>&#160;&#160;&#160; $sql = "SELECT * FROM secteur";</p>
</p>
<p>&#160;&#160;&#160; echo &#39;&#60;select&#62;&#39;;</p>
</p>
<p>&#160;&#160; &#160;$result = mysql_query($sql) or die("Couldn&#39;t execute query.".mysql_error());</p>
</p>
<p>&#160;&#160;&#160; while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {</p>
</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; echo &#39;&#60;option value="&#39;.$row[&#39;idsecteur&#39;].&#39;"&#62;&#39;.$row[&#39;secteur&#39;].&#39;&#60;/option&#62;&#39;;</p>
<p>&#160;&#160;&#160; }</p>
</p>
<p>&#160;&#160;&#160; echo &#39;&#60;/select&#62;&#39;;</p>
</p>
<p>//mysql_close($db);&#160;</p>
<p>?&#62;</p>
<p>my ddlprojet.php</p>
<p>&#60;?php</p>
<p>&#160;&#160;&#160; include("dbconfig.php");</p>
</p>
<p>&#160;&#160;&#160; if(isset($_GET[&#39;id_secteur&#39;])){</p>
<p>&#160;&#160;&#160; $id_secteur=$_GET[&#39;id_secteur&#39;];</p>
<p>&#160;&#160;&#160; $sql="select idprojet, projet, idsecteur from projet where idsecteur=$id_secteur";&#160;&#160;&#160;</p>
<p>&#160;&#160;&#160; }</p>
<p>&#160;&#160;&#160; else {</p>
</p>
<p>&#160;&#160;&#160; $sql="select projet.idprojet, projet.projet from projet inner join secteur on secteur.idsecteur=projet.idsecteur where secteur.secteur=&#39;$id_secteur&#39;";&#160;&#160;&#160;</p>
<p>&#160;&#160;&#160; //$sql="select idprojet, projet, idsecteur from projet where idsecteur=$id_secteur";&#160;&#160;&#160;</p>
<p>&#160;&#160; &#160;}&#160;&#160;&#160;</p>
</p>
<p>&#160;&#160;&#160; $rs = mysql_query($sql);</p>
<p>&#160;&#160;&#160; echo "&#60;select&#62;";&#160;</p>
<p>&#160;&#160;&#160; while ($reg=mysql_fetch_array($rs)) {</p>
<p>&#160;&#160;&#160; echo "&#60;option value=&#39;".$reg[&#39;idprojet&#39;]."&#39;&#62;".$reg[&#39;projet&#39;]."&#60;/option&#62;";</p>
<p>&#160;&#160;&#160; }</p>
<p>&#160;&#160;&#160; echo"&#60;/select&#62;";</p>
<p>&#160;&#160;&#160; mysql_close($db);</p>
<p>?&#62;</p>
<p><span style="font-size: 14px;">well I see that I&#39;m missing something but I do not see.</span></p>
<p>I can display secteur in my first dll within dataUrl but I&#39;ve proble when I edit a row, the select secteur is no good.</p>
<p><span style="font-size: 14px;">function loadsecteur(){var sect = null;$.get("ddlsecteur.php", function(data){sect = data; &#160;$(&#39;#idsecteur&#39;).html(sect);}}); &#160; &#160; &#160;</span></p>
</p>
<p>{name:&#39;idsecteur&#39;, index:&#39;idsecteur&#39;, width:80, align:&#39;right&#39;, editable:true, edittype:"select",</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; editoptions:{<span style="font-size: 14px;">value:loadsecteur,&#160;</span></p>
<p><span style="font-size: 14px;">&#160;</span><span style="font-size: 14px;">dataEvents:[{type: &#39;change&#39;,&#160;</span><span style="font-size: 14px;">fn: function(e) {var thisval = $(e.target).val();&#160;</span></p>
<p><span style="font-size: 14px;">&#160;</span><span style="font-size: 14px;">$.get(&#39;ddlprojet.php?id_secteur=&#39;+thisval,&#160;</span><span style="font-size: 14px;">function(data)</span><span style="font-size: 14px;">{ $("select#idprojet").html(data);</span><span style="font-size: 14px;">&#160;</span></p>
<p><span style="font-size: 14px;">}); // end get&#160;</span><span style="font-size: 14px;">}// end func</span><span style="font-size: 14px;">} // end type&#160;</span><span style="font-size: 14px;">] // dataevents&#160;</span><span style="font-size: 14px;">}// edit option</span><span style="font-size: 14px;">},</span></p>
</p>
<p>but how not display in the ddlprojet all item of my table projet</p>
</p>
<p>Should I change and add a function there ?</p>
<p>$("#ficheprojet").jqGrid(&#39;navGrid&#39;,&#39;#gridpager&#39;,{edit:true,add:true,del:true,search:true}, &#160;&#160;	{//prmEdit				 &#160;&#160;	closeAfterEdit:true,	viewPagerButtons:false,&#160; &#160; recreateForm:true	//refresh:true&#160; &#160; },	{//prmAdd	closeAfterAdd:true&#160; &#160; }</p>
</p>
<p>thanks for all.</p>
]]></description>
        	        	<pubDate>Mon, 18 Feb 2013 12:42:54 +0200</pubDate>
        </item>
</channel>
</rss>