EditOptions OnLoad Custom SQL

QuestionsEditOptions OnLoad Custom SQL
Hamish Borthen asked 2 years ago

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

 

 

1 Answers
Abu Ghufran Staff answered 2 years ago

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 { }.

_________________________
Abu Ghufran - Dev Team
Grid 4 PHP Framework
 
Hamish Borthen replied 2 years ago

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

Your Answer

19 + 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?