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.
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.
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;
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?
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.