Overwrite search field dropdown

QuestionsOverwrite search field dropdown
Melissa asked 6 years ago

Hi. Is it possible to overwrite the dropdown in the search modal with the result of a sql query? The dropdown is currently populated by the column names with $col[“search”] = true. What I want is to populate the search with the keys of a json object with select distinct jsonb_object_keys(document) from model.tags. Can this be done using $col[“searchoptions”] or another property? Thanks!

View post on imgur.com

4 Answers
Melissa answered 6 years ago

Another thought I had was to get the list of json keys from a query and create a column for each one. I do not know the list ahead of time so it’ll have to be done dynamically. I’ll hide these columns, but have them searchable so they’ll show up in the search dialog dropdown. My question is can we dynamically create grid columns by looping through a query result set? Thanks again.

Abu Ghufran Staff answered 6 years ago

Both of your cases are doable.

For main question, you can set:

$cols[$i][“searchoptions”][“value”] = “key1:label1; key2:label2”;

and it will be shown in search options of that column. What you can do is to run query by:

$rs = $g->get_all(“SELECT …………. FROM TABLE”); // debug $rs to know format

And feed $rs in searchoptions value manually. It is exactly what is done inside when you provide sql for dropdown.

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

Thanks. After thinking about it the better solution would be to dynamically generate columns and hide the ones we don’t want to show. How would I go about doing that? I haven’t seen it in the doc or examples. Thanks again!

Abu Ghufran Staff answered 6 years ago

If i understand correctly, To dynamically generate column, you might need to:

  1. Fetch your data using query: $rs = $g->get_all(“select …… tab”);
  2. Iterate $rs in a loop
  3. Make custom columns inside body like:

$col = array();
$col[“title”] = “col_name”;
$col[“name”] = “col_name”;
$col[“width”] = “20”;
$col[“editable”] = false;
$col[“hidden”] = true;
$cols[] = $col;

The col_name could be the field used in WHERE clause of search. You can use some there expression as well e.g.

$col[“dbname”] = “concat(table.field,table.field2)”;

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

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