Hi,
I have a table that holds an id for the customer. To have the customer’s name displayed in the grid, I’m using a LEFT JOIN, connecting the name to the id. To show the name in the table I’m:
– adding a hidden (joined) column holding the “customer_name”
– use $col["default"] ={customer_name} for the column “customer_id” to show the name (io the id)
– use $col[["edittype"] = "select” combining id:customer_name for editing
This all works well, however, the filter is still using the id-value.
Is there a way to have the filter using a different column/ field for filtering?
Hello,
For a much simpler way, please refer demos/appearence/dropdown.php
Pasting from FAQ
##### Q) How can i show lookup dropdown from other table (i.e. linked with FK data)
First step is to select the table which you want to use in grid, which will include table join.
$g->select_command = "SELECT id, invdate, invheader.client_id, amount, note FROM invheader
INNER JOIN clients on clients.client_id = invheader.client_id
";
After that, you need to define column like this.
$col = array();
$col["title"] = "Client";
$col["name"] = "client_id"; // same as aliased name (fk)
$col["dbname"] = "clients.name"; // this is required as we need to search in name field, not id
$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 client_id as k, name as v from clients");
$col["editoptions"] = array("value"=>$str);
$col["formatter"] = "select"; // show label in grid, instead of value
$cols[] = $col;
Refer dropdown.php for working demo.