Hey there im trying to add a dropdown that gets values from one table, i can make it work with autocomplete but not with selectbox, am i doing something wrong?
if i add the code down the grid doesnt load.
$col = array();
$col[“title”] = “Cliente”; // caption of column
$col[“name”] = “cliente”; // grid column name, same as db field or alias from sql
$col[“editable”] = true;
$col[“width”] = “150”;
$col[“edittype”] = “select”;
$str = $g->get_dropdown_values(“select *,nome as v From clientes”);
$col[“editoptions”][“value”] = $str;
$col[“editoptions”][“onload”][“sql”] = “select *,nome as v From clientes”;
//$col[“formatter”] = “select”; // autocomplete
//$col[“formatoptions”] = array(“sql”=>”select *,nome as v From clientes”,”search_on”=>”nome”,”force_select”=>true);
$col[“editrules”] = array(“required”=>true, “readonly”=>false);
$cols[] = $col;
Hello,
Please refer this link: https://www.gridphp.com/docs/column-options/#render-as-database-lookup-dropdown
Let me know in case of further help.
https://www.gridphp.com/demo/demos/appearance/dropdown.phps Line 68,69
https://www.gridphp.com/demo/demos/appearance/dropdown-country-city.phps Line 86-93
First of all thank you for your fast reply, it can load the dropdown now, but it keeps selecting the same value if i select any, and once selected it doesnt load the dropdown back.
$col[“edittype”] = “select”;
$str = $g->get_dropdown_values(“select *,Contrato as v From registo_obra_m order by Contrato “);
$col[“editoptions”] = array(
“value”=>”:;”.$str,
“onchange” => array(
“update_field”=>”Contrato”,”callback” => “fill_form”,
“sql”=>”select *,Contrato as v From registo_obra_m order by Contrato”, )
);
//$col[“formatter”] = “autocomplete”; // autocomplete
//$col[“formatoptions”] = array(“sql”=>”select *,Contrato as v From registo_obra_m”,”search_on”=>”Contrato”, “callback” => “fill_form”);
$col[“editable”] = true; // this column is not editable
And if i try do save the form it says to fill that field.. i cant understand what am i doing wrong
Hi,
I think, You need to set query like:
select id as k, nome as v From clientes
The alias k and v are required to make dropdown’s key and value. Please refer demo code for example.