// Code //
$col = array();
$col["title"] = "Client";
$col["name"] = "client_id";
$col["dbname"] = "clients.client_id";
$col["width"] = "100";
$col["align"] = "left";
$col["search"] = true;
$col["editable"] = true;
$col["edittype"] = "select";
# fetch data from database, with alias k for key, v for value
# on change, update other dropdown
$str = $g->get_dropdown_values("select client_id as k, name as v from clients");
$col["editoptions"] = array(
"value"=>$str,
"onchange" => array("sql"=>"select id as k, note as v from invheader WHERE client_id = '{client_id}'",
"update_field" => "note" )
);
$col["formatter"] = "select"; // display label, not value
$col["stype"] = "select";
$col["searchoptions"] = array("value" => ":;".$str);
$cols[] = $col;
$col = array();
$col["title"] = "Invoices";
$col["name"] = "note";
$col["width"] = "100";
$col["search"] = true;
$col["editable"] = true;
$col["edittype"] = "select";
$str = $g->get_dropdown_values("select id as k, note as v from invheader");
$col["editoptions"] = array("value"=>$str);
$col["editoptions"]["onload"]["sql"] = "select id as k, note as v from invheader WHERE client_id = {client_id}";
$col["stype"] = "select";
$col["searchoptions"] = array("value" => ":;".$str);
$cols[] = $col;
// Code //
When I onchange not working, help fix problem
thanks
This is supported in premium verison. If you are already using it, please check demos/appearance/dropdown-dependent.php
This works great in the add/edit form, but on the grid the dropdown is always full of all possible values, i.e. it does not update with the "onchange" event. Is there a way to do that?
You will need to add following along with onchange:
$col["editoptions"]["onload"]["sql"] = "select distinct client_id as k, name as v from clients";
Cpde: http://phpgrid.org/demo/demos/appearence/dropdown-dependent.phps