Hello,
I’ve tried to use your solution, but I don’t understand how I need to use it.
Maybe I’ve not correctly explain my problem. I try to explain differently.
Usually with some coffee I pass to solve my problem with your good advice.
My grid is only in EDIT mode, no ADD. When I open the modal EDIT windows, I want to keep the value of the ‘num_ef’ cell. And I want to use this value in the
WHERE clause in the query who populate a dropdown. Below the essential of my actual code.
Thanks for your help,
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 |
<!--?php // Load des parametres de connexion require_once '../../tb_l_connect.php'; // Load des Class jqGrid require_once "../../php/PHPSuito/jqGrid.php"; // Load des paramétres PDO pour jqGrid require_once "../../php/PHPSuito/DBdrivers/jqGridPdo.php"; // Connexion au serveur $conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD); // Déclaration du format UTF-8 de la BDD $conn->query("SET NAMES utf8");<br ?--> // Déclaration de la Class de Datepicker require_once "../../php/PHPSuito/jqCalendar.php"; // Tell the db that we use utf-8 mysql_set_charset('utf8'); // Connexion au serveur $conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD); // Déclaration du format UTF-8 de la BDD $conn->query("SET NAMES utf8"); // Création d'une instance jqGrid $grid = new jqGridRender($conn); // Load de la requête SQL $grid->SelectCommand = " SELECT <code>grid_essieu_prog</code>.<code>num_interv</code>, <code>grid_essieu_prog</code>.<code>flag</code>, <code>grid_essieu_prog</code>.<code>cle_GMAO</code>, <code>grid_essieu_prog</code>.<code>flotte</code>, <code>grid_essieu_prog</code>.<code>num_ef</code>, <code>grid_essieu_prog</code>.<code>type_di</code>, <code>grid_essieu_prog</code>.<code>statut_interv</code>, <code>grid_essieu_prog</code>.<code>lib_interv</code>, <code>grid_essieu_prog</code>.<code>pos</code>, <code>grid_essieu_prog</code>.<code>defaut</code>, <code>grid_essieu_prog</code>.<code>cote_def</code>, <code>grid_essieu_prog</code>.<code>ref_RDV</code>, <code>grid_essieu_prog</code>.<code>semaine</code>, <code>grid_essieu_prog</code>.<code>dt_butee</code>, <code>essieu_bte</code>.num_ef_bte, <code>essieu_bte</code>.<code>WR_bte</code>, <code>essieu_bte</code>.<code>statut_bte</code>, <code>essieu_bte</code>.<code>Notes_bte</code>, <code>essieu_bte</code>.<code>dt_creat</code>, <code>essieu_bte</code>.<code>dt_gmao</code>, <code>essieu_bte</code>.<code>dt_real</code>, IF(essieu_bte.WR_bte!='','0','1') AS CTRL FROM <code>grid_essieu_prog</code> LEFT JOIN <code>essieu_bte</code> ON <code>grid_essieu_prog</code>.<code>lib_interv</code>=<code>essieu_bte</code>.<code>WR_bte</code> AND (<code>grid_essieu_prog</code>.<code>num_ef</code>=<code>essieu_bte</code>.num_ef_bte) WHERE essieu_bte.statut_bte ='Confirmé / Initialisé' OR essieu_bte.statut_bte ='En cours' OR essieu_bte.statut_bte ='Ouvert') "; // Déclaration de la table MaJ $grid->table = 'essieu_interv'; // Définition d'une clé primaire $grid->setPrimaryKeyId("num_interv"); $grid->serialKey = true; //Déclaration du format d'échange en json $grid->dataType = 'json'; // Déclaration du model du grid $grid->setColModel(); // Déclaration du fichier origine des données $grid->setUrl('grid_prog.php'); // Déclaration d'autres options $grid->setGridOptions(array( "caption"=>"programmation", // Titre du tableau "rowNum"=>10, // Nombre de lignes par défaut à afficher "rowList"=>array(20,35,50,70,120), // Déclaration du nombres de lignes affichables "sortname"=>"num_interv", // Déclaration du tri par défaut "sortorder"=>"desc", // Ordre de tri des lignes "width"=>"1650", // Largeur du tableau en px "loadonce" =>false, "toppager"=>true, // "colMenu"=>true, "height"=>"auto", // Hauteur automatique du tableau "hoverrows"=>true // highlight la ligne survolée )); //********************************* $grid->setColProperty('cle_GMAO', array( "hidden"=>true, "width"=>85, "align"=>"center", "classes"=>"wr", "editable"=>false)); //$grid->setColProperty('flag', array( "hidden"=>false, "label"=>"Etat","width"=>55, "align"=>"center", "editable"=>false)); $grid->setColProperty('num_interv', array( "hidden"=>true, "width"=>85, "align"=>"center", "classes"=>"wr", "editable"=>false)); //$grid->setColProperty('num_ef', array("label"=>"Engin", "width"=>50, "align"=>"center", "classes"=>"wr", "editoptions"=>array("readonly"=>true))); $grid->setColProperty('flotte', array("label"=>"Flotte", "align"=>"center", "width"=>50)); $grid->setColProperty('num_ef', array("label"=>"N° EF", "width"=>55)); // **************************************** // --Propriété Champ dropdown $grid->setColProperty('ref_RDV', array("label"=>"Ref RDV", "width"=>60, "editable"=>true,"align"=>"center", "classes"=>"wr", "editrules"=>array("required"=>false))); $grid->setSelect("ref_RDV", "SELECT <code>ID_RDV</code>,<code>ID_RDV</code> FROM <code>drop_ref_rdv</code> ORDER BY <code>ID_RDV</code> ASC",false,true,true); $grid->setColProperty('defaut', array("label"=>"Déf origine", "width"=>90, "editable"=>true,"align"=>"center", "classes"=>"wr", "editrules"=>array("required"=>false))); $grid->setAutocomplete("defaut",false,"SELECT DISTINCT lib_def FROM drop_essieu_def WHERE num_ef LIKE ? ORDER BY lib_def",null,true,false); // **************************************** // --Regroupement de colonnes $grid->callGridMethod("#grid0", "setGroupHeaders", array(array( "useColSpanStyle"=>true, "groupHeaders"=>array( array( "startColumnName"=>'flag', "numberOfColumns"=>12, "titleText"=>'Extract Works Report' ), array( "startColumnName"=>'WR_bte', "numberOfColumns"=>6, "titleText"=>'Extract BTE' ) ) ))); // **************************************** $grid->debug = false; // Configuration du navigateur $grid->navigator = true; // Activation des options d'édition $grid->setNavOptions('navigator', array("excel"=>true, "pdf"=>true, "add"=>false,"edit"=>true,"del"=>true,"view"=>true, "search"=>true, "cloneToTop"=>true)); // Fermeture de la fenetre d'édition apres validation //$grid->setNavOptions('add',array("closeAfterAdd"=>true, "width"=>600, "left"=>300, "dataheight"=>375, "height"=>450, "top"=>250, "editCaption"=>"Ajout","bSubmit"=>"Ajouter", "viewPagerButtons"=>false)); $grid->setNavOptions('edit',array("closeAfterEdit"=>true,"width"=>600, "left"=>300, "dataheight"=>475, "height"=>550, "top"=>250, "editCaption"=>"Modification","bSubmit"=>"MAJ", "viewPagerButtons"=>false)); $grid->setNavOptions('search',array("multipleSearch"=>true, "uniqueSearch"=>true, "uniqueSearchFields"=>true)); $grid->renderGrid('#grid0','#pager',true, null, null, true,true); $conn = null; ?> |
Jqgrid PHP 5.1.0
Hello,
Thanks, it’s all right !!! With your solution, the both functions work fine.
Kind Regards,
Saroumane
Jqgrid PHP 5.1.0
Hello,
Sorry for my late answer. I would like use only the value of the first dropdown in the search dialog windows.
I understand that it is not easy to use the different level of the dependent dropdown in the search windows.
Kinds Regards,
Thierry
Jqgrid PHP 5.1.0
Hello Tony,
I followed your advice, and I create a variable that=this. After this change, the second dropdown work fine, but not the third dropdown. In the console, the N3val variable is not filled. var N3val = $("#unites2",formid).val();
I created a variable var N3val = selc3;
and my third dropdown seems to work fine.
What do think about this solution?
Kind Regards,
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 |
$beforeshowedit = <<< BEFORESHOW2 function(formid) { var that = this; var sr = jQuery(that).jqGrid('getGridParam','selrow'); var selc = jQuery(that).jqGrid('getCell',sr,'UO'); 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 += ""+item.value+""; } else { t += ""+item.value+""; } }); jQuery("#UO",formid).html("").append(t); } }); // Prend la valeur du menu déroulant 1 var cntryval = $("#UO",formid).val(); console.log ("cntryval:"+cntryval); jQuery("#unites2",formid).html("Select"); 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=""; console.log ("t:"+t); console.log ("sr:"+sr); if(sr) { // récupére le menu N2 dans le Grid sv = jQuery(that).jqGrid('getCell',sr,'unites2'); console.log ("sv:"+sv); jQuery.each(response, function(i,item) { t += ""+item.value+""; }); // 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(that).jqGrid('getGridParam','selrow'); var selc3 = jQuery(that).jqGrid('getCell',sr,'unites2'); console.log ("selc3:"+selc3); 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 += ""+item.value+""; } else { t3 += ""+item.value+""; } }); jQuery("#unites2",formid).html("").append(t); } }); // Prend la valeur du menu déroulant 2 // var N3val = $("#unites2",formid).val(); var N3val = selc3; console.log ("N3val:"+N3val); jQuery("#pilote",formid).html("Select"); 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=""; console.log ("N3val:"+N3val); console.log ("t3:"+t3); console.log ("sv3:"+sv3); console.log ("sr3:"+sr3); if(sr3) { // récupére le menu 3 dans le Grid sv3 = jQuery(that).jqGrid('getCell',sr3,'pilote'); jQuery.each(response, function(i,item) { console.log ("sv3:"+sv3); t3 += ""+item.value+""; }); // 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; |
Jqgrid PHP 5.1.0
Hello,
thanks for your hell Tony.
I remplaced the variable ($subtable)
by (this)
in this part of code:
1 2 3 4 |
function(formid) { var sr = jQuery(this).jqGrid('getGridParam','selrow'); var selc = jQuery(this).jqGrid('getCell',sr,'UO'); |
Now the first dropdown is OK, but the second dropdown is empty and the third display “select”. I think the “q” variable is not fill.
I changed all ($subtable) variable by (this) everywherein the script, but the dropdowns are not OK.
What do you think about this new problem ?
Thank,
PS: Sorry my english is poor.
The “beforeshow edit” script
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 |
$beforeshowedit = <<< BEFORESHOW2 function(formid) { var sr = jQuery(this).jqGrid('getGridParam','selrow'); var selc = jQuery(this).jqGrid('getCell',sr,'UO'); 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>"); 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(this).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(this).jqGrid('getGridParam','selrow'); var selc3 = jQuery(this).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(this).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; |
Jqgrid PHP 5.1.0
Hello,
Thanks for your Help. It’s OK now !!!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
// Option d'édition Time datepicker $grid->setColProperty('date_at', array("formatter"=>"date", "label"=>"Date événement","align"=>"center", "width"=>100, "editable"=>true, "formatoptions"=>array("reformatAfterEdit"=>true, "srcformat"=>"Y-m-d H:i:s", "newformat"=>"d/m/Y H:i"), "editoptions"=>array("dataInit"=> "js:function(elm){setTimeout(function(){ jQuery(elm).datetimepicker({dateFormat:'dd/mm/yy'}); jQuery('.ui-datepicker').css({'font-size':'75%'}); },200);}"), "searchoptions"=>array("dataInit"=> "js:function(elm){setTimeout(function(){ jQuery(elm).datetimepicker({dateFormat:'dd/mm/yy'}); jQuery('.ui-datepicker').css({'font-size':'75%'}); },200);}" ))); |
Kind Regards,
Sarou
Jqgrid PHP 5.1.0
Hello,
Thanks. Your proposition work very well when I declare the “primary key” in the master php file.
Kind Regards,
Saroumane.
Jqgrid PHP 5.1.0
Hello,
I followed your advice, and I tested this modification.
The grid is ok, and my 3 levels dropdown work fine.
But can you read my code and tell me what you think about this.
Kind Regards,
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 |
<!--?php // Load des parametres de connexion require_once '../rex_at-config.php'; // Load des Class jqGrid require_once "../../php/PHPSuito/jqGrid.php"; // Load des paramétres PDO pour jqGrid require_once "../../php/PHPSuito/DBdrivers/jqGridPdo.php"; // Load des paramétres français pour jqGrid require_once "../../php/PHPSuito/External/tcpdf/config/lang/fra.php"; mysql_set_charset('utf8'); // Connexion au serveur $conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD); // Déclaration du format UTF-8 de la BDD $conn->query("SET NAMES utf8");</p> <p> // Création d'une instance jqGrid<br ?--> $grid = new jqGridRender($conn); // Load de la requête SQL $grid->SelectCommand = 'SELECT id_at, type, date_at, uo_poles, unites, description, commentaires, nom, prenom, CP, jeune_embauche, arret, duree_arret, code1, code2 , code3, lesion, siege, epi, DPA_trait, DPA_valid FROM rex_at'; // Déclaration de la table MaJ $grid->table = 'rex_at'; // Définition d'une clé primaire $grid->setPrimaryKeyId("id_at"); $grid->serialKey = false; //Déclaration du format d'échange en json $grid->dataType = 'json'; // Déclaration du model du grid $grid->setColModel(); // Déclaration du fichier origine des données $grid->setUrl('grid_rex_at.php'); // Déclaration d'autres options $grid->setGridOptions(array( "caption"=>"Saisie REX des AT TMV", // Titre du tableau "rowNum"=>15, // Nombre de lignes par défaut à afficher "rowList"=>array(20,35,50), // Déclaration du nombres de lignes affichables "sortname"=>"date_at", // Déclaration du tri par défaut "sortorder"=>"desc", // Ordre de tri des lignes "width"=>1900, // Largeur du tableau en px "height"=>"Auto", // Hauteur automatique du tableau "hoverrows"=>true // highlight la ligne survolée )); // **************************************** // Règle d'édition des champs par défaut $grid->setColProperty('id_at', array("editoptions"=>array("readonly"=>true))); $grid->setColProperty('id_at', array("hidden"=>true)); $grid->setColProperty('type', array("label"=>"Type", "width"=>70, "align"=>"center", "editable"=>true)); $grid->setColProperty('uo_poles', array("label"=>"UO/Pôles", "width"=>90, "align"=>"center", "editable"=>true, "classes"=>"cvteste")); $grid->setColProperty('unites', array("label"=>"Unités", "width"=>90, "align"=>"left", "editable"=>true)); $grid->setColProperty('nom', array("label"=>"Nom", "width"=>90, "align"=>"left", "editable"=>true)); $grid->setColProperty('prenom', array("label"=>"Prénom", "width"=>70, "align"=>"left", "editable"=>true)); $grid->setColProperty('CP', array("label"=>"Num CP", "width"=>60, "align"=>"center", "editable"=>true)); $grid->setColProperty('jeune_embauche', array("label"=>"J-emb", "align"=>"center", "width"=>40, "editable"=>true)); $grid->setColProperty('arret', array("label"=>"Arrêt", "width"=>25, "align"=>"center", "editable"=>true)); $grid->setColProperty('lesion', array("label"=>"Lésion", "width"=>60, "editable"=>true)); $grid->setColProperty('duree_arret', array("label"=>"Durée arrêt", "width"=>60, "align"=>"center", "editable"=>true,"formatter"=>"integer", "formatoptions"=>array("suffix"=>" jours"))); $grid->setColProperty('siege', array("label"=>"Siège", "width"=>40, "align"=>"center", "editable"=>true)); $grid->setColProperty('epi', array("label"=>"EPI", "width"=>20, "align"=>"center", "editable"=>true)); $grid->setColProperty('DPA_trait', array("label"=>"Traite DPA", "width"=>50, "align"=>"center", "editable"=>true, "formatter"=>"integer", "formatoptions"=>array("suffix"=>" jours"))); $grid->setColProperty('DPA_valid', array("label"=>"Valid DPA", "width"=>50, "align"=>"center", "editable"=>true, "formatter"=>"integer", "formatoptions"=>array("suffix"=>" jours"))); // **************************************** // règle d'édition des champs dropdown $grid->setColProperty('code2', array("edittype"=>"select","label"=>"Codage N2", "width"=>110, "align"=>"left","editoptions"=>array("value"=>" :Select"))); $grid->setColProperty('code1', array("edittype"=>"select", "label"=>"Codage N1", "width"=>110, "align"=>"left","editoptions"=>array("value"=>" :Select"))); $grid->setColProperty('code3', array("edittype"=>"select", "label"=>"Codage N3", "width"=>110, "align"=>"left","editoptions"=>array("value"=>" :Select"))); $grid->setSelect("type", "SELECT champ_type, champ_type FROM drop_type_at ORDER BY champ_type ASC",false,true,true); $grid->setSelect("uo_poles", "SELECT pole, pole FROM menu_pole ORDER BY pole ASC",false,true,true); $grid->setSelect("unites", "SELECT unite, unite FROM <code>menu_unite</code> ORDER BY <code>unite</code> ASC ",false,true,true); $grid->setSelect("lesion", "SELECT <code>lesion</code>,<code>lesion</code> FROM <code>drop_lesion</code> ORDER BY <code>lesion</code> ASC",false,true,true); $grid->setSelect("siege", "SELECT <code>siege</code>,<code>siege</code> FROM <code>drop_siege</code> ORDER BY <code>siege</code> ASC",false,true,true); $grid->setSelect("jeune_embauche", "SELECT Choix,Choix FROM drop_choix_o_n ORDER BY Choix ASC",false,true,true); $grid->setSelect("arret", "SELECT Choix,Choix FROM drop_choix_o_n ORDER BY Choix ASC",false,true,true); $grid->setSelect("epi", "SELECT Choix,Choix FROM drop_choix_o_n ORDER BY Choix ASC",false,true,true); // **************************************** // Champ en zone de texte $grid->setColProperty('description', array("label"=>"Description", "edittype"=> 'textarea',"editoptions"=>array("rows"=>4, "cols"=>50, "maxlength"=>255, "width"=>120), "width"=>200, "editable"=>true)); $grid->setColProperty('commentaires', array("label"=>"Commentaires", "edittype"=> 'textarea',"editoptions"=>array("rows"=>4, "cols"=>50, "maxlength"=>255, "width"=>120), "width"=>100, "editable"=>true)); // **************************************** // Option d'édition Time datepicker $grid->setColProperty('date_at', array("label"=>"Date événement","align"=>"center", "width"=>100,"formatter"=>"date", "formatoptions"=>array("reformatAfterEdit"=>true, "srcformat"=>"Y-m-d H:i:s", "newformat"=>"d/m/Y H:i"), // Ok. We use some trick here to create the datepicker on dataInit event // when the element is created. Note the js: before the function. // this instruct the grid to put a javascript code without additional formating "editoptions"=>array("dataInit"=> "js:function(elm){setTimeout(function(){ jQuery(elm).datetimepicker({dateFormat:'dd/mm/yy'}); jQuery('.ui-datepicker').css({'font-size':'75%'}); },0);}") )); $grid->setDbTime('Y-m-d H:i:s'); $grid->setUserTime("d/m/Y H:i"); // **************************************** // Fonction de génération des menus déroulants en cascade $beforeshowadd = <<< BEFORESHOW function(formid) { // jQuery.ajax({ url: 'drop_N1.php', dataType: 'json', async : false, // envoi q:1 dans le cas d'ajout ou de modification drop_N1.php data: {q:1}, data: {z:1}, success : function(response) { var t="Select"; jQuery.each(response, function(i,item) { t += ""+item.value+""; }); jQuery("#code1",formid).html("").append(t); } }); jQuery("#code2",formid).html("Select"); } BEFORESHOW; $beforeshowedit = <<< BEFORESHOW2 function(formid) { var sr = jQuery("#grid").jqGrid('getGridParam','selrow'); var selc = jQuery("#grid").jqGrid('getCell',sr,'code1'); jQuery.ajax({ url: 'drop_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 += ""+item.value+""; } else { t += ""+item.value+""; } }); jQuery("#code1",formid).html("").append(t); } }); // Prend la valeur du menu déroulant 1 var cntryval = $("#code1",formid).val(); jQuery("#code2",formid).html("Select"); if(cntryval) { // Si la valeur est trouvée, utilise AJAX pour obtenir les valeurs de Niv 2 // SVP regarder le fichier drop_N2.php jQuery.ajax({ url: 'drop_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,'code2'); jQuery.each(response, function(i,item) { t += ""+item.value+""; }); // vide la selection et ajoute la nouvelle valeur jQuery("#code2",formid).html("").append(t); if(sv) { // sélectionne la valeur du menu N2 jQuery("#code2",formid).val(sv).removeAttr("disabled"); } } } }); } else { jQuery("#code2",formid).attr("disabled","disabled"); } var sr3 = jQuery("#grid").jqGrid('getGridParam','selrow'); var selc3 = jQuery("#grid").jqGrid('getCell',sr,'code2'); jQuery.ajax({ url: 'drop_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 += ""+item.value+""; } else { t3 += ""+item.value+""; } }); jQuery("#code2",formid).html("").append(t); } }); // Prend la valeur du menu déroulant 2 var N3val = $("#code2",formid).val(); // var N3val = "Sol glissant"; jQuery("#code3",formid).html("Select"); if(N3val) { // Si la valeur est trouvée, utilise AJAX pour obtenir les valeurs de Niv 3 // SVP regarder le fichier drop_N3.php jQuery.ajax({ url: 'drop_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("#grid").jqGrid('getCell',sr3,'code3'); jQuery.each(response, function(i,item) { t3 += ""+item.value+""; }); // vide la selection et ajoute la nouvelle valeur jQuery("#code3",formid).html("").append(t3); if(sv3) { // sélectionne la valeur du menu N2 jQuery("#code3",formid).val(sv3).removeAttr("disabled"); } } } }); } else { jQuery("#code3",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("#code1",formid).change(function(e) { var cntryval = $(this).val(); if(cntryval) { jQuery("#code2",formid).html(""); jQuery.ajax({ url: 'drop_N2.php', dataType: 'json', data: {q:cntryval}, success : function(response) { var t=""; jQuery.each(response, function(i,item) { t += ""+item.value+""; }); jQuery("#code2",formid).append(t).removeAttr("disabled"); } }); } }); jQuery("#code2",formid).change(function(e) { var N3val = $(this).val(); if(N3val) { jQuery("#code3",formid).html(""); jQuery.ajax({ url: 'drop_N3.php', dataType: 'json', data: {z:N3val}, success : function(response) { var t3=""; jQuery.each(response, function(i,item) { t3 += ""+item.value+""; }); jQuery("#code3",formid).append(t3).removeAttr("disabled"); } }); } }); // fin de test menu lvl 3 } INITFORM; // ***************** Fin du script des menus en cascade *********************** // **************************************** // Parametrage des export Excel et PDF $grid->exportfile = 'Export_retard_tmv.xls'; // Définition du nom du fichier d'export Excel $oper = jqGridUtils::GetParam("oper"); // Parametre d'exportation PDF if($oper == "pdf") { $grid->setPdfOptions(array( "page_orientation"=>"L", // Orientation de la page en paysage "L" ou portrait "P" "header"=>true, // Activation d'un entête "margin_top"=>20, // Déclaration d'une en-tete de haut de page "margin_bottom"=>0, // Déclaration d'une en-tete de bas de page "margin_footer"=>5, "header_logo"=>"logo.gif", // Nom d'un logo dans répertioire PDF php/ tcpdf "header_logo_width"=>20, //Déclaration de la largeur du logo "header_title"=>"Export retard sortie de site", // Titre de l'en-tête "shrink_cell"=>false, // Activation/Desactivation du tassement des valeurs "encoding" => "UTF-8", // Encodage UTF-8 "reprint_grid_header"=>true, // Affichage des titres de colonnes sur chaque page "header_string"=>"Technicentre de Villeneuve" // Texte d'en-tête à imprimer )); } //********************************* // **************************************** // Configuration du navigateur $grid->navigator = true; // Activation des options d'édition $grid->setNavOptions('navigator', array("excel"=>true,"add"=>true,"edit"=>true,"del"=>true,"view"=>true, "search"=>true)); // Fermeture de la fenetre d'édition apres validation $grid->setNavOptions('edit',array("closeAfterEdit"=>true,"editCaption"=>"Update Customer","bSubmit"=>"Update", "viewPagerButtons"=>false)); // 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); $grid->renderGrid('#grid','#pager',true, null, null, true,true); $conn = null; ?> |
Jqgrid PHP 5.1.0
Hello,
Thank for your fast answer. I will waiting the end of the week.
Kind Regards,
Saroumane
Jqgrid PHP 5.1.0
Hello Will,
I changed my code by following your advice, but I have no change. The second dropdown is empty in the edit form. The field is not filled by the value, and the dropdown is empty. I need to choose again a value in the first dropdown for populate again the second dropdown.
My code with change:
1 2 3 4 |
sv = jQuery("#test1").jqGrid('getCell',sr,'code1'); jQuery.each(response, function(i,item) { t += "<option value='"+item.id+"'>"+item.value+"</option>"; }); |
Thanks for your help.
Kind Regards,
Jqgrid PHP 5.1.0
Hello Tony,
I’m sorry for my confusion about the log.
I’m used the console log from firebug, and I have this result when I edit a row:
1 2 |
q Objets, masses, particules en mouvement accidentel |
1 2 |
[{"id":"Autre particule (sauf projection de produit chimiq","value":"Autre particule (sauf projection de produit chimiq"},{"id":"Effondrement de mati\u00e8res stock\u00e9es ou empil\u00e9es","value":"Effondrement de mati\u00e8res stock\u00e9es ou empil\u00e9es"},{"id":"El\u00e9ment de v\u00e9hicule ferroviaire","value":"El\u00e9ment de v\u00e9hicule ferroviaire"},{"id":"El\u00e9ment mobile","value":"El\u00e9ment mobile"},{"id":"Non class\u00e9 ci-dessous","value":"Non class\u00e9 ci-dessous"},{"id":"Objet, masse","value":"Objet, masse"},{"id":"Particule imputable au tranchage ou \u00e0 la frappe","value":"Particule imputable au tranchage ou \u00e0 la frappe"},{"id":"Particule imputable aux autres machines","value":"Particule imputable aux autres machines"},{"id":"Particule imputable aux meules","value":"Particule imputable aux meules"},{"id":"Produit d'\u00e9boulement ou d'effondrement","value":"Produit d'\u00e9boulement ou d'effondrement"},{"id":"Produits caustique, corrosif, toxique","value":"Produits caustique, corrosif, toxique"}] |
If I’m understand the log, the ‘q’ value’ is ok, the function load the result of the query for the second dropdown, but don’t fill this, or don’t bind the result.
A problem with the JSON file ?
Thanks for your answer.
Jqgrid PHP 5.1.0
In fact, if I modify my form without update my depndent dropdown, I have this log:
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 |
Executed 1 query(s) - 2015-08-21 10:57:04 Array ( [0] => Array ( [time] => 2015-08-21 10:57:04 [query] => SELECT * FROM rex_at WHERE 1=2 [data] => [types] => [fields] => [primary] => [input] => ) ) Executed 2 query(s) - 2015-08-21 10:57:04 Array ( [0] => Array ( [time] => 2015-08-21 10:57:04 [query] => SELECT * FROM rex_at WHERE 1=2 [data] => [types] => [fields] => [primary] => [input] => ) [1] => Array ( [time] => 2015-08-21 10:57:04 [query] => UPDATE rex_at SET date_at = ?, type = ?, uo_poles = ?, unites = ?, description = ?, commentaires = ?, nom = ?, prenom = ?, CP = ?, jeune_embauche = ?, arret = ?, duree_arret = ?, code1 = ?, code2 = ?, lesion = ?, siege = ?, epi = ?, DPA_trait = ?, DPA_valid = ? WHERE id_at = ? [data] => Array ( [0] => 2014-04-01 09:10:00 [1] => Refusé [2] => Tous UO/Pôles [3] => Informatique local [4] => test [5] => test2 [6] => BARJOT [7] => THIERRY [8] => 7008095v [9] => Non [10] => Non [11] => 0jours [12] => Accessoires de levage, amarrage et préhension [13] => Select [14] => [15] => [16] => [17] => 0jours [18] => 0jours [19] => 187 ) [types] => Array ( [0] => datetime [1] => string [2] => string [3] => string [4] => string [5] => string [6] => string [7] => string [8] => string [9] => blob [10] => blob [11] => numeric [12] => string [13] => string [14] => string [15] => string [16] => blob [17] => numeric [18] => numeric [19] => int ) [fields] => Array ( [id_at] => Array ( [type] => int ) [date_at] => Array ( [type] => datetime ) [type] => Array ( [type] => string ) [uo_poles] => Array ( [type] => string ) [unites] => Array ( [type] => string ) [description] => Array ( [type] => string ) [commentaires] => Array ( [type] => string ) [nom] => Array ( [type] => string ) [prenom] => Array ( [type] => string ) [CP] => Array ( [type] => string ) [jeune_embauche] => Array ( [type] => blob ) [arret] => Array ( [type] => blob ) [duree_arret] => Array ( [type] => numeric ) [code1] => Array ( [type] => string ) [code2] => Array ( [type] => string ) [lesion] => Array ( [type] => string ) [siege] => Array ( [type] => string ) [epi] => Array ( [type] => blob ) [DPA_trait] => Array ( [type] => numeric ) [DPA_valid] => Array ( [type] => numeric ) ) [primary] => id_at [input] => Array ( [id_at] => 187 [type] => Refusé [date_at] => 01/04/2014 09:10 [uo_poles] => Tous UO/Pôles [unites] => Informatique local [description] => test [commentaires] => test2 [nom] => BARJOT [prenom] => THIERRY [CP] => 7008095v [jeune_embauche] => Non [arret] => Non [duree_arret] => 0jours [code1] => Accessoires de levage, amarrage et préhension [code2] => Select [lesion] => [siege] => [epi] => [DPA_trait] => 0jours [DPA_valid] => 0jours [oper] => edit ) ) ) Executed 2 query(s) - 2015-08-21 10:57:04 Array ( [0] => Array ( [time] => 2015-08-21 10:57:04 [query] => SELECT COUNT(*) AS COUNTR FROM rex_at [data] => [types] => [fields] => [primary] => [input] => ) [1] => Array ( [time] => 2015-08-21 10:57:04 [query] => SELECT id_at, type, date_at, uo_poles, unites, description, commentaires, nom, prenom, CP, jeune_embauche, arret, duree_arret, code1, code2, lesion, siege, epi, DPA_trait, DPA_valid FROM rex_at ORDER BY date_at desc LIMIT 75, 15 [data] => [types] => [fields] => [primary] => [input] => ) |
Jqgrid PHP 5.1.0
Hello Tony,
Thank for your answer.
I verified my code with your indications. I added the line
1 2 3 |
console.log(sv); if(sv) |
and the log file give this information:
log file:
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 |
Executed 1 query(s) - 2015-08-21 10:15:03 Array ( [0] => Array ( [time] => 2015-08-21 10:15:03 [query] => SELECT * FROM rex_at WHERE 1=2 [data] => [types] => [fields] => [primary] => [input] => ) ) Executed 2 query(s) - 2015-08-21 10:15:03 Array ( [0] => Array ( [time] => 2015-08-21 10:15:03 [query] => SELECT * FROM rex_at WHERE 1=2 [data] => [types] => [fields] => [primary] => [input] => ) [1] => Array ( [time] => 2015-08-21 10:15:03 [query] => UPDATE rex_at SET date_at = ?, type = ?, uo_poles = ?, unites = ?, description = ?, commentaires = ?, nom = ?, prenom = ?, CP = ?, jeune_embauche = ?, arret = ?, duree_arret = ?, code1 = ?, code2 = ?, lesion = ?, siege = ?, epi = ?, DPA_trait = ?, DPA_valid = ? WHERE id_at = ? [data] => Array ( [0] => 2014-04-01 09:10:00 [1] => Refusé [2] => Tous UO/Pôles [3] => Informatique local [4] => test [5] => test [6] => BARJOT [7] => THIERRY [8] => 7008095v [9] => Non [10] => Non [11] => 0jours [12] => Accessoires de levage, amarrage et préhension [13] => Cordage textile [14] => [15] => [16] => [17] => 0jours [18] => 0jours [19] => 187 ) [types] => Array ( [0] => datetime [1] => string [2] => string [3] => string [4] => string [5] => string [6] => string [7] => string [8] => string [9] => blob [10] => blob [11] => numeric [12] => string [13] => string [14] => string [15] => string [16] => blob [17] => numeric [18] => numeric [19] => int ) [fields] => Array ( [id_at] => Array ( [type] => int ) [date_at] => Array ( [type] => datetime ) [type] => Array ( [type] => string ) [uo_poles] => Array ( [type] => string ) [unites] => Array ( [type] => string ) [description] => Array ( [type] => string ) [commentaires] => Array ( [type] => string ) [nom] => Array ( [type] => string ) [prenom] => Array ( [type] => string ) [CP] => Array ( [type] => string ) [jeune_embauche] => Array ( [type] => blob ) [arret] => Array ( [type] => blob ) [duree_arret] => Array ( [type] => numeric ) [code1] => Array ( [type] => string ) [code2] => Array ( [type] => string ) [lesion] => Array ( [type] => string ) [siege] => Array ( [type] => string ) [epi] => Array ( [type] => blob ) [DPA_trait] => Array ( [type] => numeric ) [DPA_valid] => Array ( [type] => numeric ) ) [primary] => id_at [input] => Array ( [id_at] => 187 [type] => Refusé [date_at] => 01/04/2014 09:10 [uo_poles] => Tous UO/Pôles [unites] => Informatique local [description] => test [commentaires] => test [nom] => BARJOT [prenom] => THIERRY [CP] => 7008095v [jeune_embauche] => Non [arret] => Non [duree_arret] => 0jours [code1] => Accessoires de levage, amarrage et préhension [code2] => Cordage textile [lesion] => [siege] => [epi] => [DPA_trait] => 0jours [DPA_valid] => 0jours [oper] => edit ) ) ) Executed 2 query(s) - 2015-08-21 10:15:03 Array ( [0] => Array ( [time] => 2015-08-21 10:15:03 [query] => SELECT COUNT(*) AS COUNTR FROM rex_at [data] => [types] => [fields] => [primary] => [input] => ) [1] => Array ( [time] => 2015-08-21 10:15:03 [query] => SELECT id_at, type, date_at, uo_poles, unites, description, commentaires, nom, prenom, CP, jeune_embauche, arret, duree_arret, code1, code2, lesion, siege, epi, DPA_trait, DPA_valid FROM rex_at ORDER BY date_at desc LIMIT 75, 15 [data] => [types] => [fields] => [primary] => [input] => ) ) Executed 2 query(s) - 2015-08-21 10:15:45 Array ( [0] => Array ( [time] => 2015-08-21 10:15:45 [query] => SELECT COUNT(*) AS COUNTR FROM rex_at [data] => [types] => [fields] => [primary] => [input] => ) [1] => Array ( [time] => 2015-08-21 10:15:45 [query] => SELECT id_at, type, date_at, uo_poles, unites, description, commentaires, nom, prenom, CP, jeune_embauche, arret, duree_arret, code1, code2, lesion, siege, epi, DPA_trait, DPA_valid FROM rex_at ORDER BY date_at desc LIMIT 0, 15 [data] => [types] => [fields] => [primary] => [input] => ) ) |
If I see correctly the log, the value of dependent dropdown are loaded, but no displayed. It’s right ? but I don’t understand why.
Thanks for your help,
Kind Regards
Jqgrid PHP 5.1.0
Hello,
Thank for your answrer,
I’ve not really understand your first proposition, but I think your second idea solve my problem.
Thanks,
Kind Regards,
Jqgrid PHP 5.1.0
Hello,
Thanks for your answer. Sorry for my English, I’m French.
I would like to use a variable coming from a previous form for choose the users groups. Currently, the variable “UO” is fixed in the request for my tests.
The objective is that the users groups (the field “UO”) see only the rows of the main grid which relate them, and only the subgrid rows where they are present.
Thanks for your help.
Kind Regards,
Jqgrid PHP 5.1.0
Copyright 2014 TriRand LtdAll Rights ReservedRSS
Back to Top