Use dropdown values

QuestionsUse dropdown values
diana asked 3 years ago

Hi, can I use the values of a get_dropdown_values of a column in another column? for example: the var $str2 of the column area I want to use in the query of another column or How can I get the value the user select for that dropdown?

//------------------Area
$col = array();
$col["formatter"] = "select";
$col["title"] = "Área";
$col["name"] = "id_area";
$col["width"] = "60";
$col["editable"] = true; 
$col["align"] = "center"; 
$col["search"] = false; 
# fetch data from database, with alias k for key, v for value
$area_lookup = $g->get_dropdown_values("select distinct id_area as k, nombre_area as v from inventario_produccion.areas ORDER by id_area");
# these 3 lines will make dropdown in search autofilter
$col["stype"] = "select";
// all row, blank row, then all db values. ; is separator
$str2 = ":;".$area_lookup;
$col["searchoptions"] = array("value" => $str2, "separator" => ":", "delimiter" => ";");
$col["edittype"] = "select"; // render as select
$col["editoptions"] = array("value"=>":;".$area_lookup); // with these values "key:value;key:value;key:value"
$cols[] = $col;
 //---------------Articulo
$col = array();
$col["formatter"] = "select";
$col["title"] = "Artículo";
$col["name"] = "codigo_articulo";
$col["width"] = "80";
$col["editable"] = true; 
$col["align"] = "center"; 
$col["search"] = false; 
$col["editoptions"] = array("size"=>35);
# fetch data from database, with alias k for key, v for value
$str = $g->get_dropdown_values("SELECT articulos_areas.codigo_articulo, concat_ws(' ',nombre_articulo,tipo,nombre_marca)
FROM inventario_produccion.articulos_areas,inventario_produccion.articulos, inventario_produccion.marcas
where id_area = ".$str2." and articulos_areas.codigo_articulo = articulos.codigo_articulo and articulos.id_marca = marcas.id_marca");
$col["edittype"] = "select"; // render as select
$col["editoptions"] = array("value"=>":;".$str);
$col["editoptions"]["dataInit"] = "function(){ setTimeout(function(){ link_select2('{$col["name"]}'); },200); }";
$col["stype"] = "select"; // render as select
$col["searchoptions"] = array("value"=>$str); 
$col["searchoptions"]["dataInit"] = "function(){ setTimeout(function(){ link_select2('gs_{$col["name"]}');},200);}";
$cols[] = $col;
1 Answers
Abu Ghufran Staff answered 3 years ago

In first dropdown, you need to define onchange option mentioned field-to-update and sql query. e.g.

$sql = "SELECT articulos_areas.codigo_articulo, concat_ws(' ',nombre_articulo,tipo,nombre_marca)
FROM inventario_produccion.articulos_areas,inventario_produccion.articulos, inventario_produccion.marcas
where id_area = '{id_area}' and articulos_areas.codigo_articulo = articulos.codigo_articulo and articulos.id_marca = marcas.id_marca";

$col["editoptions"] = array("value"=>":;".$area_lookup);
$col["editoptions"]["onchange"] = array( "update_field" => "codigo_articulo", "sql" => $sql );

For working example, refer demos/appearance/dropdown-dependent.php

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
diana replied 3 years ago

thanks, I’m gonna try it

Your Answer

10 + 9 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?