Hi,
I want to restrict the values in a drop down to those matching the parent company_id as per below.
However when I load up the edit dialog I get a “Internal 500 errror” and the drop down populates with all address values – suggesting it’s using the the initial get_dropdown_values(“”) query.
$col = array();
$col[“title”] = “Billing Address”;
$col[“name”] = “billing_address_id”;
$col[“dbname”] = “a.street”; // this is required as we need to search in name field, not id
$col[“width”] = “80”;
$col[“align”] = “left”;
$col[“hidden”] = false;
$col[“search”] = true;
$col[“editable”] = true;
$col[“editrules”] = array(“required”=>false);
$col[“edittype”] = “select”;
$str = $grid->get_dropdown_values(“select distinct c.address_id as k, c.street as v from company_address c “);
$col[“editoptions”] = array(“value”=>”:;”.$str);
$col[“editoptions”][“onload”][“sql”] = “select distinct address_id as k, street as v from company_address where company_id = {company_id} order by v”;
$col[“formatter”] = “select”; // display label, not value
$col[“export”] = false;
$cols[] = $col;
To me it looks like the {company_id} insertion may not be working on the onload portion of the query.
Please assist 🙂
THanks,
Hamish
Hello,
Yes you are correct. Most likely the company_id is not replaced in query.
Make sure you have a grid column with name:
$col[“name”] = “company_id”;
Only fields defined in columns of grid are replaced in sql query with placeholder { }.
Thanks Abu, however there is still an issue as I do have that column.
Later in the code I have this code which works fine showing the substitution is working.
$actions = “”;
$col = array();
$col[“title”] = “Actions”;
$col[“name”] = “buttons”;
$col[“default”] = $actions;
$col[“width”] = “140”;
$col[“align”] = “center”;
$col[“search”] = false;
$col[“sortable”] = false;
$cols[] = $col;
Still unsure what it could be