Home › Forums › Guriddo Suito PHP › Dropdown with filter
Tagged: dropdown query filter
Hi,
I would like to make a dropdown menu with a WHERE clause. The dropdown is populate by a SQL query and the value come from another cell in the row.
How I can keep this value in my query ?
This menu is only used in EDIT mode and the value of the WHERE clause is fixed for each row.
Sorry from my poor english ( I’m french)
Kind Regards
Thierry
Jqgrid PHP 5.1.0
Hello,
As far as I understand the problem you can use dataUrl option as function. In this case you can get the value from the other cell and pass it as parameter to the datUrl.
Here is a demo of this
Look at file detail.php. The related code is like this:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
$select = <<<SELECT function(rowid, value, name) { var srow = jQuery("#grid").jqGrid('getGridParam','selrow'); if(srow) { // get the row data based on the selected id var gridrow = jQuery("#grid").jqGrid('getRowData',srow); // pas it to the url return "select.php?id_emp="+gridrow.EmployeeID; } } SELECT; $grid->setColProperty("EmployeeID",array("edittype"=>"select", "hidden"=>false,"width"=>20,"editoptions"=>array("dataUrl"=>"js:".$select))); |
The select.php look like this:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
require_once '../../jq-config.php'; // include the jqGrid Class require_once ABSPATH."php/PHPSuito/jqGridUtils.php"; // include the driver class require_once ABSPATH."php/PHPSuito/DBdrivers/jqGridPdo.php"; // Connection to the server $conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD); // Tell the db that we use utf-8 jqGridDB::query($conn,"SET NAMES utf8"); $empid = jqGridUtils::GetParam('id_emp'); // Get details $SQL = "SELECT * FROM employees WHERE EmployeeID <=".(int)$empid; $qres = jqGridDB::query($conn, $SQL); // $result = jqGridDB::fetch_assoc($qres,$conn); $s = "<select>"; while($result = jqGridDB::fetch_assoc($qres,$conn) ) { $s .= "<option>".$result['FirstName']." ".$result['LastName'].'</option>'; } $s .= "</select>"; echo $s; jqGridDB::closeCursor($qres); |
Please let us know if this solves your problem.
Kind Regards,
Will
Guriddo Support Team
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,
If I understand correct the requirement you are close to the solution provided in previous post.
Actually you do not need to use setSelect. The code with the setSelect
|
1 2 3 4 5 |
... $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 ID_RDV,ID_RDV FROM drop_ref_rdv ORDER BY ID_RDV ASC",false,true,true); ... |
can be replaced with this one
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
$grid->setColProperty('ref_RDV', array("label"=>"Ref RDV", "width"=>60, "editable"=>true, "align"=>"center", "classes"=>"wr", "edittype"=>"select", "editoptions"=>array("dataUrl"=>"js:".$select), "editrules"=>array("required"=>false))); $select = <<<SELECT function(rowid, value, name) { var srow = jQuery("#grid0").jqGrid('getGridParam','selrow'); if(srow) { // get the row data based on the selected id var gridrow = jQuery("#grid").jqGrid('getRowData',srow); // pas it to the url return "select.php?num_ef="+gridrow.num_ef; } } SELECT; |
and the file select.php can have the following
|
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 |
require_once '../../jq-config.php'; // include the jqGrid Class require_once ABSPATH."php/PHPSuito/jqGridUtils.php"; // include the driver class require_once ABSPATH."php/PHPSuito/DBdrivers/jqGridPdo.php"; // Connection to the server $conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD); // Tell the db that we use utf-8 jqGridDB::query($conn,"SET NAMES utf8"); $numief = jqGridUtils::GetParam('num_ef'); // Get details $SQL = "SELECT ID_RDV,ID_RDV FROM drop_ref_rdv WHERE /*your where here/* ORDER BY ID_RDV ASC"; $qres = jqGridDB::query($conn, $SQL); // $result = jqGridDB::fetch_assoc($qres,$conn); $s = "<select>"; while($result = jqGridDB::fetch_assoc($qres,$conn) ) { $s .= "<option>".$result['ID_RDV'].'</option>'; } $s .= "</select>"; echo $s; jqGridDB::closeCursor($qres); &nbsp; |
Hope I understand correct the problem
Kind Regards,
Will
Guriddo Support Team
Copyright 2014 TriRand LtdAll Rights ReservedRSS
Back to Top