Hello,
I have a new problem đ .
I have make a dependent dropdown in a subgrid. This dropdown is OK in simple grid, but the same code in a subgrid in the edit mode ( the add mode is OK) don’t work.
In first field of dropdown he first value of the query appears instead of the save value in database.
The console log say for the (sr) variable :Â Â Â Â Â sr: undefined
Have you an idea for solve my problem ?
Thanks for your help,
The subgrid:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
require_once '../PAS-config.php'; // include the jqGrid Class require_once "../php/PHPSuito/jqGrid.php"; // include the driver class require_once "../php/PHPSuito/DBdrivers/jqGridPdo.php"; require_once "../php/PHPSuito/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 $oper = jqGridUtils::GetParam("oper"); $subtable = jqGridUtils::GetParam("grid_PAS_sub"); //$subtable = jqGridUtils::GetParam("subgrid"); $rowid = jqGridUtils::GetParam("rowid"); //if(!$subtable && !$rowid) die("Missed parameters"); // Create the jqGrid instance $grid = new jqGridRender($conn); $grid->debug = false; // Write the SQL Query $grid->SelectCommand = "SELECT <code>seconde</code>.id_detail, <code>seconde</code>.CustomerID, <code>seconde</code>.description, <code>seconde</code>.UO, <code>seconde</code>.unites2, <code>seconde</code>.pilote, <code>seconde</code>.commentair, <code>seconde</code>.contributeur, <code>seconde</code>.planif_deb_2,<code>seconde</code>.planif_fin_2,<code>seconde</code>.date_modif, <code>seconde</code>.date_real, <code>seconde</code>.etat_avance, <code>seconde</code>.comment FROM <code>seconde</code> WHERE seconde.CustomerID = ?"; // set the ouput format to json $grid->dataType = 'json'; $grid->setPrimaryKeyId('id_detail'); // Let the grid create the model $grid->setColModel(null,array(&$rowid)); // Set the url from where we obtain the data $grid->setUrl('../PAS/grid_PAS_sub.php'); $grid->table = 'seconde'; // Set some grid options $grid->setGridOptions(array( "height"=>"Auto", // Hauteur automatique du tableau "hoverrows"=>true, // highlight la ligne survolĂ©e "caption"=>"Action UO/PĂŽle 2", // Titre du tableau "width"=>1670, "rowList"=>array(20,35,50), // DĂ©claration du nombres de lignes affichables "rowNum"=>10, "sortname"=>"id_detail", // "postData"=>array("grid_PAS_sub"=>$subtable,"rowid"=>$rowid))); "postData"=>array("subgrid"=>$subtable,"rowid"=>$rowid))); //$grid->setNavOptions("add",array("editData"=>array("CustomerID"=>$rowid))); // Changement des propriĂ©tĂ©s des champs. $grid->setColProperty('CustomerID', array("hidden"=>true,"editable"=>false)); $grid->setColProperty('id_detail', array("label"=>"RĂ©f dĂ©tail", "hidden"=>true,"editable"=>false, "width"=>60)); $grid->setColProperty('contributeur', array("label"=>"Contributeur", "width"=>100)); // champ zone de texte. $grid->setColProperty('description', array("label"=>"Description Action UO/PĂŽle", "editpilote"=> 'textarea',"editoptions"=>array("style"=>"width:98%;"), "width"=>250, "editable"=>true)); $grid->setColProperty('commentair', array("label"=>"Commentaire Pilote Action", "editpilote"=> 'textarea',"editoptions"=>array("style"=>"width:98%;"), "width"=>200, "editable"=>true)); $grid->setColProperty('comment', array("label"=>"Commentaire QSE", "editpilote"=> 'textarea',"editoptions"=>array("style"=>"width:98%;"), "width"=>200, "editable"=>true)); // **************************************** //Champ date Datepicker $grid->setColProperty('date_modif', array("label"=>"Date modif","align"=>"center", "width"=>80,"formatter"=>"date", // DĂ©fini le champ comme un champ ""date"" "formatoptions"=>array("srcformat"=>"Y-m-d","newformat"=>"d/m/Y"), // DĂ©fini le format d'affichage en jj/mm/aaaa "search"=>true )); // Autorise la recherche sur ce champ $grid->setDatepicker('date_modif', array("buttonIcon"=>true, 'changeMonth'=> true), true, true); // Active le Datepicker en mode bouton $grid->datearray = array('date_modif'); // DĂ©claration du champ contenant une date $grid->SetUserDate("d/m/Y"); // Configuration de l'affichage de la date cotĂ© utilisateur // ------- $grid->setColProperty('date_real', array("label"=>"Date rĂ©alisation","align"=>"center", "width"=>80,"formatter"=>"date", // DĂ©fini le champ comme un champ ""date"" "formatoptions"=>array("srcformat"=>"Y-m-d","newformat"=>"d/m/Y"), // DĂ©fini le format d'affichage en jj/mm/aaaa "search"=>true)); // Autorise la recherche sur ce champ $grid->setDatepicker('date_real', array("buttonIcon"=>true, 'changeMonth'=> true), true, true); // Active le Datepicker en mode bouton $grid->datearray = array('date_real'); // DĂ©claration du champ contenant une date $grid->SetUserDate("d/m/Y"); // Configuration de l'affichage de la date cotĂ© utilisateur // ------- $grid->setColProperty('planif_deb_2', array("label"=>"DĂ©but planif","align"=>"center", "width"=>80,"formatter"=>"date", // DĂ©fini le champ comme un champ ""date"" "formatoptions"=>array("srcformat"=>"Y-m-d","newformat"=>"d/m/Y"), // DĂ©fini le format d'affichage en jj/mm/aaaa "search"=>true)); // Autorise la recherche sur ce champ $grid->setDatepicker('planif_deb_2', array("buttonIcon"=>true, 'changeMonth'=> true), true, true); // Active le Datepicker en mode bouton $grid->datearray = array('planif_deb_2'); // DĂ©claration du champ contenant une date $grid->SetUserDate("d/m/Y"); // Configuration de l'affichage de la date cotĂ© utilisateur // ------- $grid->setColProperty('planif_fin_2', array("label"=>"Fin planif","align"=>"center", "width"=>80,"formatter"=>"date", // DĂ©fini le champ comme un champ ""date"" "formatoptions"=>array("srcformat"=>"Y-m-d","newformat"=>"d/m/Y"), // DĂ©fini le format d'affichage en jj/mm/aaaa "search"=>true)); // Autorise la recherche sur ce champ $grid->setDatepicker('planif_fin_2', array("buttonIcon"=>true, 'changeMonth'=> true), true, true); // Active le Datepicker en mode bouton $grid->datearray = array('plannif_fin_2'); // DĂ©claration du champ contenant une date $grid->SetUserDate("d/m/Y"); // Configuration de l'affichage de la date cotĂ© utilisateur // **************************************** // champ avec menu dĂ©roulant $grid->setColProperty('etat_avance', array("label"=>"avancement", "width"=>60,"align"=>"center", "editable"=>true, "formatter"=>"integer", "formatoptions"=>array("elmprefix"=>"(*)", "suffix"=>" %",))); $grid->setSelect("etat_avance", "SELECT avance,avance FROM <code>menu_avancement</code> ORDER BY <code>avance</code> ASC ",false,true,true); $grid->setColProperty('UO', array("edittype"=>"select", "label"=>"UO/PĂŽle", "width"=>70, "align"=>"left", "editoptions" => array("value"=>" :Select"))); $grid->setColProperty('pilote', array("edittype"=>"select","label"=>"Pilote", "width"=>70, "align"=>"left", "editoptions" => array("value"=>" :Select"))); $grid->setColProperty('unites2', array("edittype"=>"select", "label"=>"UnitĂ©s", "width"=>70, "align"=>"left", "editoptions" => array("value"=>" :Select"))); // $grid->setColProperty('unites', array("label"=>"UnitĂ©s", "width"=>80)); // $grid->setSelect("unites", "SELECT <code>unites</code>,<code>unites</code> FROM <code>menu_unite</code> ORDER BY unites ASC",false,true,true); // **************************************** // <---------------------------------------------> // Fonction de gĂ©nĂ©ration des menus dĂ©roulants en cascade des responsables $beforeshowadd = <<< BEFORESHOW function(formid) { // jQuery.ajax({ url: 'drop_uo_n1.php', dataType: 'json', async : false, // envoi q:1 dans le cas d'ajout ou de modification drop_uo_n1.php data: {q:1}, data: {z:1}, success : function(response) { var t="<option value=''>Select</option>"; jQuery.each(response, function(i,item) { t += "<option value='"+item.id+"'>"+item.value+"</option>"; }); jQuery("#UO",formid).html("").append(t); } }); jQuery("#unites2",formid).html("<option>Select</option>"); } BEFORESHOW; $beforeshowedit = <<< BEFORESHOW2 function(formid) { var sr = jQuery("$subtable").jqGrid('getGridParam','selrow'); var selc = jQuery("$subtable").jqGrid('getCell',sr,'UO'); console.info("sr:",sr); console.log("selc:",selc); console.log("selc:",selc); console.log("selc:",selc); jQuery.ajax({ url: 'drop_uo_n1.php', dataType: 'json', async : false, // Ne pas envoyer q en cas d'ajout ou de modif success : function(response) { var t=""; jQuery.each(response, function(i,item) { if( selc == item.id) { t += "<option value='"+item.id+"' selected='selected'>"+item.value+"</option>"; } else { t += "<option value='"+item.id+"'>"+item.value+"</option>"; } }); jQuery("#UO",formid).html("").append(t); } }); // Prend la valeur du menu dĂ©roulant 1 var cntryval = $("#UO",formid).val(); jQuery("#unites2",formid).html("<option>Select</option>"); console.log(cntryval); if(cntryval) { // Si la valeur est trouvĂ©e, utilise AJAX pour obtenir les valeurs de Niv 2 // SVP regarder le fichier drop_uo_n2.php jQuery.ajax({ url: 'drop_uo_n2.php', dataType: 'json', data: {q:cntryval}, success : function(response) { var t="", sv=""; if(sr) { // rĂ©cupĂ©re le menu N2 dans le Grid sv = jQuery("#grid").jqGrid('getCell',sr,'unites2'); jQuery.each(response, function(i,item) { t += "<option value='"+item.id+"'>"+item.value+"</option>"; }); // vide la selection et ajoute la nouvelle valeur jQuery("#unites2",formid).html("").append(t); if(sv) { // sĂ©lectionne la valeur du menu N2 jQuery("#unites2",formid).val(sv).removeAttr("disabled"); } } } }); } else { jQuery("#unites2",formid).attr("disabled","disabled"); } var sr3 = jQuery("$subtable").jqGrid('getGridParam','selrow'); var selc3 = jQuery("$subtable").jqGrid('getCell',sr,'unites2'); jQuery.ajax({ url: 'drop_uo_n2.php', dataType: 'json', async : false, // Ne pas envoyer q en cas d'ajout ou de modif success : function(response) { var t3=""; jQuery.each(response, function(i,item) { if( selc3 == item.id) { t3 += "<option value='"+item.id+"' selected='selected'>"+item.value+"</option>"; } else { t3 += "<option value='"+item.id+"'>"+item.value+"</option>"; } }); jQuery("#unites2",formid).html("").append(t); } }); // Prend la valeur du menu dĂ©roulant 2 var N3val = $("#unites2",formid).val(); jQuery("#pilote",formid).html("<option>Select</option>"); if(N3val) { // Si la valeur est trouvĂ©e, utilise AJAX pour obtenir les valeurs de Niv 3 // SVP regarder le fichier drop_uo_N3.php jQuery.ajax({ url: 'drop_uo_N3.php', dataType: 'json', data: {z:N3val}, success : function(response) { var t3="", sv3=""; if(sr3) { // rĂ©cupĂ©re le menu 3 dans le Grid sv3 = jQuery("$subtable").jqGrid('getCell',sr3,'pilote'); jQuery.each(response, function(i,item) { t3 += "<option value='"+item.id+"'>"+item.value+"</option>"; }); // vide la selection et ajoute la nouvelle valeur jQuery("#pilote",formid).html("").append(t3); if(sv3) { // sĂ©lectionne la valeur du menu N2 jQuery("#pilote",formid).val(sv3).removeAttr("disabled"); } } } }); } else { jQuery("#pilote",formid).attr("disabled","disabled"); } // fin de test menu lvl 3 } BEFORESHOW2; // Avec cet Ă©vĂ©nement nous lions un changement au niveau du premier dropdown // Si une nouvelle valeur est choisi, nous faisons un appel AJAX pour avoir les valeurs du second dropdown liĂ© au premier // Notez que cet Ă©vĂ©nement doit ĂȘtre exĂ©cutĂ©e une seule fois si le formulaire est construit. $initform = <<< INITFORM function(formid) { jQuery("#UO",formid).change(function(e) { var cntryval = $(this).val(); if(cntryval) { jQuery("#unites2",formid).html(""); jQuery.ajax({ url: 'drop_uo_n2.php', dataType: 'json', data: {q:cntryval}, success : function(response) { var t=""; jQuery.each(response, function(i,item) { t += "<option value='"+item.id+"'>"+item.value+"</option>"; }); jQuery("#unites2",formid).append(t).removeAttr("disabled"); } }); } }); jQuery("#unites2",formid).change(function(e) { var N3val = $(this).val(); if(N3val) { jQuery("#pilote",formid).html(""); jQuery.ajax({ url: 'drop_uo_n3.php', dataType: 'json', data: {z:N3val}, success : function(response) { var t3=""; jQuery.each(response, function(i,item) { t3 += "<option value='"+item.id+"'>"+item.value+"</option>"; }); jQuery("#pilote",formid).append(t3).removeAttr("disabled"); } }); } }); // fin de test menu lvl 3 } INITFORM; // ***************** Fin du script des menus en cascade *********************** // set a option when we add a record to insert a CustomerID too. $grid->setNavOptions("add",array("editData"=>array("CustomerID"=>$rowid))); $grid->setSubGridGrid ("../PAS/grid_PAS_subsub.php"); $grid->navigator = true; $grid->setNavOptions('navigator', array("excel"=>false,"add"=>true,"edit"=>true,"del"=>true,"view"=>true)); $grid->setNavOptions('edit', array("editCaption"=>"MaJ Action Niveau UO/pĂŽle","height"=>'auto',"dataheight"=>"auto","width"=>'1000',"top"=>'50', "left"=>'100',"closeAfterEdit" => true)); // ParamĂštre du formulaire d'Ă©dition $grid->setNavOptions('add', array("CustomerID"=>$rowid, "addCaption"=>"Nouvelle Action UO/pĂŽle","closeAfterAdd"=>true,"height"=>'auto',"dataheight"=>"auto","width"=>'1000',"top"=>'50', "left"=>'100')); // Liaison des fonctions avant l'ouverture du formulaire $grid->setNavEvent('edit', 'beforeShowForm', $beforeshowedit); $grid->setNavEvent('add', 'beforeShowForm', $beforeshowadd); // Liaison des fonctions en cas de modifications $grid->setNavEvent('edit', 'onInitializeForm', $initform); $grid->setNavEvent('add', 'onInitializeForm', $initform); // Enjoy $subtable = $subtable."_t"; $pager = $subtable."_p"; $grid->renderGrid($subtable,$pager, true, null, array(&$rowid), true,true); |
Jqgrid PHP 5.1.0
Copyright 2014 TriRand LtdAll Rights ReservedRSS
Back to Top