Dropdown get values

QuestionsDropdown get values
Joel Gomes asked 2 years ago

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;

2 Answers
Abu Ghufran Staff answered 2 years ago

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

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Joel Gomes replied 2 years ago

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

Joel Gomes replied 2 years ago

And if i try do save the form it says to fill that field.. i cant understand what am i doing wrong

Abu Ghufran Staff answered 2 years ago

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.

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Your Answer

10 + 16 =

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?