Default Value in Dropdown

QuestionsDefault Value in Dropdown
Alfonso Cabrera asked 9 years ago

Hi Abu!

I will like to make in the parameter "editoptions" a default value when ever I add a record to the grid.

$col = array();
$col["title"] = "Status"; // caption of column
$col["name"] = "status"; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
$col["editable"] = true;
$col["edittype"] = "select"; // render as select
$str5 = "1:Nuevo;2:En Proceso;3:Resuelto;4:No resuelto";
$col["stype"] = "select"; // enable dropdown search
$col["editoptions"] = array("defaultValue" => "Nuevo");
$col["searchoptions"] = array("value" => ":;".$str5);
$col["formatter"] = "select"; // display label, not value
$col["width"] = 100;
$cols[] = $col;

I create this code but it doesn't display anything when I want to select the option Nuevo when I add a record.

I need the first option (1:Nuevo) to be the default one.

4 Answers
Abu Ghufran answered 9 years ago

You can replace edtoptions with:

$col["editoptions"] = array("value"=>$str5, "defaultValue" => "1");

Alfonso Cabrera answered 9 years ago

Hi Abu!

With this configuration of the dropdown, I can select the 4 options, but now I want only to show the first element, not the rest of the list.

When the user adds new records, it should only pick the 1st element, but I can't trust the user, so I need the dropdown with only one option to select.

In the other hand, another user different from who created the record should change this column to the other 3 options.

How can I make this column editable when the user adds records and not editable when he wants to update the record?

I've already tried different options, like using the defaultValue but it seems not to work, because it displays the other 3 options, I don't want that.

Thanks.

Abu Ghufran answered 9 years ago

If you want to show only first element when adding, you can remove other options using js code.

$opt["add_options"]["afterShowForm"] = 'function () { $("#status").children("option:not(:first)").remove(); }';
$g->set_options($opt);

This will remove all status except first only for add dialog, and let it run as usual for edit.

migul answered 9 years ago

necesito colaborador proyecto , no se ingles y mecuesta enterarme en el forum
soy de cadiz , trabajo en proyecto con base de datos oficiales
a ser posible viva por andalucia y que tenga experiencia DBA
[email protected]

ruego mail y tfno

Your Answer

6 + 15 =

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?