Dropdown select

QuestionsDropdown select
Adrian asked 4 years ago
Hi.
I need to do a dropdown select on add form.
Show me two concatenated fields, and be able to search in any of those fields.

$col = array();
$col[“title”] = “Practica Medica”;
$col[“name”] = “prestacion”;
$col[“dbname”] = “concat(llx_prestacion.codprestacion,’ – ‘,llx_prestacion.nombreprestacion)”; // this is required as we need to search in name field, not id
$col[“width”] = “100”;
$col[“align”] = “center”;
$col[“search”] = true;
$col[“editable”] = true;

$col[“edittype”] = “select”; // render as select
# fetch data from database, with alias k for key, v for value
$str = $g->get_dropdown_values(“select distinct rowid as k, concat(llx_prestacion.codprestacion,’ – ‘,llx_prestacion.nombreprestacion) as v from llx_prestacion”);
$col[“editoptions”] = array(“value”=>”:;”.$str,”defaultValue” =>1,”style”=>”width:350px”);
$col[“show”] = array(“list”=>true,”edit”=>true,”add”=>true); // only show in add/edit dialog
//$col[“editoptions”][“dataInit”] = “function(){ setTimeout(function(){ $(‘select[name=client_id]’).select2({width:’80%’, dropdownCssClass: ‘ui-widget ui-jqdialog’}); },200); }”;
$cols[] = $col;

Now I can only search by the field llx_prestacion.codprestacion. and I need to search for either one

Thanks.

 

4 Answers
Abu Ghufran Staff answered 4 years ago

Your code looks fine and it should search in both field as mentioned here. I can’t find issue unless i test more.

concat(llx_prestacion.codprestacion,’ – ‘,llx_prestacion.nombreprestacion)

I am sending you a working demo that uses same approach.

https://gist.github.com/28ed9ad62cbcde7b5c4e1fd597934757 line 60 (override on dev/appearance/dropdown.php)

You can also try check mysql query log and see what query it being executed.

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Adrian answered 4 years ago

I have a table, three fields. id – codprestacion – nombreprestacion What I want is to be able to search by code or by name. As I have it, I can only search by codprestacion. The search should be by (contain codprestacion) or (contain nombreprestacion). It is understood? $col = array(); $col[\”title\”] = \”Practica Medica\”; $col[\”name\”] = \”prestacion\”; $col[\”dbname\”] = \”concat(llx_prestacion.codprestacion,\’ – \’,llx_prestacion.nombreprestacion)\”; // this is required as we need to search in name field, not id $col[\”width\”] = \”100\”; $col[\”align\”] = \”center\”; $col[\”search\”] = true; $col[\”editable\”] = true; $col[\”edittype\”] = \”select\”; // render as select # fetch data from database, with alias k for key, v for value $str = $g->get_dropdown_values(\”select distinct rowid as k, concat(llx_prestacion.codprestacion,\’ – \’,llx_prestacion.nombreprestacion) as v from llx_prestacion\”); $col[\”editoptions\”] = array(\”value\”=>\”:;\”.$str,\”defaultValue\” =>1,\”style\”=>\”width:350px\”); $col[\”show\”] = array(\”list\”=>true,\”edit\”=>true,\”add\”=>true); // only show in add/edit dialog //$col[\”editoptions\”][\”dataInit\”] = \”function(){ setTimeout(function(){ $(\’select[name=client_id]\’).select2({width:\’80%\’, dropdownCssClass: \’ui-widget ui-jqdialog\’}); },200); }\”; $cols[] = $col;

Adrian answered 4 years ago

I have a table, three fields. id – codprestacion – nombreprestacion What I want is to be able to search by code or by name. As I have it, I can only search by codprestacion. The search should be by (contain codprestacion) or (contain nombreprestacion). It is understood?

 

 

Abu Ghufran Staff answered 4 years ago

The demo code that i sent do exactly this. It allows searching via client ID or client Name.

See screencast: https://streamable.com/lbtgg

Code: https://gist.github.com/28ed9ad62cbcde7b5c4e1fd597934757 line 60 (override on dev/appearance/dropdown.php)

Let me know in case of further query.

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

20 + 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?