non-database dropdown

Questionsnon-database dropdown
Ken asked 7 years ago

I have a dropdown (for regions) in an include member. It's an array. How can I get it to display the data in a dropdown? I have the 'member' included and it works in other programs that don't use this grid quite well. I'm also able to successfully use a database table for a 'select'. But how do I get the data from this "include" member into my dropdown. Here is what I've tried (stateList['US'] is in the included code):

$col = array();
//$states_arr = arrayToSelect($stateList['US'], $remitToState);
$col["title"] = "AP State"; // caption of column, can use HTML tags too
$col["name"] = "remitToState"; // grid column name, same as db field or alias from sql
$col["dbname"] = "remitToState";
$col["width"] = "35";
$col["search"] = true;
$col["editable"] = true;
$col["edittype"] = "select"; // render as select
//$str = $g->get_dropdown_values(arrayToSelect($stateList['US'], $remitToState));
$str = $g->get_dropdown_values(array(arrayToSelect($stateList['US'])));
//$col["editoptions"] = arrayToSelect($stateList['US'], $remitToState);
//$col["editoptions"] = array($stateList['US']);
$col["editoptions"] = array("value"=>":;".$str);
//$col["formatter"] = "select"; // display label, not value
//$col["stype"] = "select";
$cols[] = $col;

3 Answers
Abu Ghufran answered 7 years ago

Hi,

Pasting from docs:

To render as select (dropdown),with static values "key:value;key:value;key:value"

$col["edittype"] = "select";
$col["editoptions"] = array("value"=>'10:$10;20:$20;30:$30;40:$40;50:$50');

You need to iterate array to make similar string and pass to "value" param. The get_dropdown_values() do exactly that from sql query.

Ken answered 7 years ago

Ok, I tried what I THINK you said. I have an array of State values and names, so I did this (stateList contains the states, like 'AL' => 'Alabama',) etc ..:

$col = array();
$str = (($stateList['US'])) ;
$col["title"] = "AP State";
$col["name"] = "remitToState";
$col["dbname"] = "remitToState";
$col["width"] = "35";
$col["search"] = true;
$col["editable"] = true;
$col["edittype"] = "select"; // render as select
$col["editoptions"] = array("value"=>":;".$str);
$col["formatter"] = "select";
$cols[] = $col;

This gives me a value of "undefined" in the dropdown. I really don't want to have to "hard-code" these 50 state values in a 'select' for each column that I need them in. Am I doing something wrong here? The variable $str contains the array of state keys and values.

Abu Ghufran answered 7 years ago

$str = (($stateList['US'])) ;

should be

$arr = array();
foreach($stateList as $k=>$v)
$arr[] = "$k:$v";
$str = implode(";",$arr);

Your Answer

1 + 6 =

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?