Filtering when using $col["default"]

QuestionsFiltering when using $col["default"]
Richard Kooijman asked 11 years ago

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?

1 Answers
Abu Ghufran answered 11 years ago

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.

Your Answer

3 + 5 =

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?