selected value in select in edit form

Questionsselected value in select in edit form
Hello Abu asked 9 years ago

Hi all,

I have a master-detail subgrid (clients -> actions). In this subgrid (actions) I have a filed for the client id and want I to add and edit the records. When adding or editing the records in the subgrid the clients are shown as a select field. The marked client in the master grid should be the preselected value in the select field.
Any idea?
Here is the code of the subgrid field.

$col = array();
$col["title"] = "Zielkontakt";
$col["name"] = "ziel";
$col["align"] = "left";
$col["search"] = true;
$col["editable"] = true;
$col["edittype"] = "select";
$col["formatter"] = "select";
$str = $g->get_dropdown_values("select distinct id as k, concat(name,', ',vname) as v from clients ");
$col["editoptions"]["onload"]["sql"] = "select distinct id as k, concat(name,', ',name) as v from cients";

$col["editoptions"] = array(
"value"=>$str,
"onchange" => array( "sql"=>"select distinct id as k, concat(name,', ',name) as v from clients id = '{ziel}'",
"update_field" => "id" )
);
$cols[] = $col;

4 Answers
Abu Ghufran answered 9 years ago

You can select the master row id in by following code in subgrid (actions) page.

$master_id = $_REQUEST["rowid"];
$opt["add_options"]["afterShowForm"] = 'function() { jQuery("input[name=ziel]").val( '.$master_id.' ) }';

$g->set_options($opt);

After the form is displayed it uses jQuery to reselect the master row id in ziel field.
Please recheck the jquery syntax using firebug console error.

Hello Abu answered 9 years ago

Hi Abu,

hmm, it doesn't work out.
With my code the selected master client is preselected in the edit mode, but not in the add mode.
Your code results no changes to that.

Abu Ghufran answered 9 years ago

Ok, you can try following:

$opt["add_options"]["afterShowForm"] = 'function() { var selr = jQuery("#list1").jqGrid("getGridParam","selrow"); jQuery("#ziel").val( selr ) }';

// where list1 is master grid id and ziel is column name.
http://pastebin.com/1tXB3cMN

Hello Abu answered 9 years ago

Hi Abu,

great, that's working, thx very much.

Michael

Your Answer

14 + 11 =

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?