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;
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.
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.
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