variable from subgridparams not usable

Questionsvariable from subgridparams not usable
Andreas asked 11 years ago

Hi all,

I have a problem using the Master Detail Grid feature with phpgrid version 1.5. Here the relevant code passage:

master grid:
$opt["detail_grid_id"] = "list83,list84,list85";
// extra params passed to detail grid, column name comma separated
$opt["subgridparams"] = "id_customer";
$grid->set_options($opt);

detail grid:

// receive id, selected row of parent grid
$id = intval($_GET["rowid"]);
$idCustomer = intval($_GET["id_customer"]);

$col_detail_5 = array();
$col_detail_5["title"] = "Address";
$col_detail_5["name"] = "id_facilityAddress";
$col_detail_5["width"] = "45";
$col_detail_5["align"] = "left";
$col_detail_5["search"] = false;
$col_detail_5["editable"] = true;
$col_detail_5["editrules"] = array("edithidden"=>true);
$col_detail_5["hidden"] = true;
$col_detail_5["edittype"] = "select"; // render as select
# fetch data from database, with alias k for key, v for value
$str = $grid->get_dropdown_values("SELECT id_customerAddress as k, CONCAT(addressStreet,' / ',addressZIP,' / ',addressCity) as v FROM customerAddress WHERE id_customer = $idCustomer;");
$col_detail_5["editoptions"] = array(
"value"=>$str,
// "onchange" => array("sql"=>"SELECT id_facility as k, facilitySN as v FROM facility WHERE id_facilityAddress = '{id_facilityAddress}'",
"onchange" => array("sql"=>"SELECT f.id_facility as k, CONCAT(f.facilitySN,' / ',p.facilityPN,' / ', t.typeName) as v FROM facility f INNER JOIN facilityPartNumber p ON f.id_facilityPN = p.id_facilit
"update_field" => "id_facility")
);
$col_detail_5["stype"] = "select"; // enable dropdown search
$col_detail_5["searchoptions"] = array("value" => ":;".$str);
$col_detail_5["formatter"] = "select"; // display label, not value
$cols_detail_5[] = $col_detail_5;

I have verified, that the content of $idCustomer is containing the correct values but I always get an empty dropdown field, only when I hardcode the value in the SELECT statement I get the correct entry in the dropdown list.

I suppose that the variable is not correctly evaluated.

How can this be resolved ?

Thank you for your kind help.

best regards

Andreas

5 Answers
Abu Ghufran answered 11 years ago

Hello Andreas,

I am emailing you a demo to use master param in detail's dropdown.

The key code is:

$col = array();
$col["title"] = "Client";
$col["name"] = "client_id";
$col["editable"] = true;
$col["edittype"] = "select"; // render as select

$str = $grid->get_dropdown_values("select distinct client_id as k, name as v from clients");
$col["editoptions"] = array("value"=>$str);

$col["editoptions"]["onload"]["sql"] = "select distinct client_id as k, name as v from clients WHERE client_id = $id";

$col["formatter"] = "select"; // display label, not value
$cols[] = $col;

Andreas answered 11 years ago

Hello Abu,

I have tested the "onload" option and the first dropdown list is now correctly populated, but the "onchange" "update_field" instruction does not seem to work in combination with the onload directive. What I want to achieve is to load some values in the first dropdown dependent on a master grid value and a second dropdown with values dependent on the choosen entry of the first dropdown. When I change/select a different value in first dropdown the second dropdown is filled with values from dropdown one.

1st dropdown:

$col_detail_5 = array();
$col_detail_5["title"] = "Adresse";
$col_detail_5["name"] = "id_facilityAddress";
$col_detail_5["width"] = "45";
$col_detail_5["align"] = "left";
$col_detail_5["search"] = false;
$col_detail_5["editable"] = true;
$col_detail_5["editrules"] = array("edithidden"=>true);
$col_detail_5["hidden"] = true;
$col_detail_5["edittype"] = "select"; // render as select
# fetch data from database, with alias k for key, v for value
$str = $grid->get_dropdown_values("SELECT id_customerAddress as k, CONCAT(addressStreet,' / ',addressZIP,' / ',addressCity) as v FROM customerAddress");
$col_detail_5["editoptions"] = array(
"value"=>$str,
"onload" => array("sql"=>"SELECT id_customerAddress as k, CONCAT(addressStreet,' / ',addressZIP,' / ',addressCity) as v FROM customerAddress WHERE id_customer = $idCustomer;"
"onchange" => array("sql"=>"SELECT f.id_facility as k, CONCAT(f.facilitySN,' / ',p.facilityPN,' / ', t.typeName) as v FROM facility f INNER JOIN facilityPartNumber p ON f.id_facilityPN = p.id_facilityPN INNER JOIN type t ON p.id_type = t.id_type WHERE f.id_facilityAddress = '{id_facilityAddress}'",
"update_field" => "id_facility")
);
$col_detail_5["stype"] = "select"; // enable dropdown search
$col_detail_5["searchoptions"] = array("value" => ":;".$str);
$col_detail_5["formatter"] = "select"; // display label, not value
$cols_detail_5[] = $col_detail_5;

2nd dropdown:

$col_detail_5 = array();
$col_detail_5["title"] = "Anlage SN / Typ / Anlagenart ";
$col_detail_5["name"] = "id_facility";
$col_detail_5["width"] = "45";
$col_detail_5["align"] = "left";
$col_detail_5["search"] = false;
$col_detail_5["editable"] = true;
$col_detail_5["editrules"] = array("edithidden"=>true);
$col_detail_5["hidden"] = false;
$col_detail_5["edittype"] = "select"; // render as select
# fetch data from database, with alias k for key, v for value
$str = $grid->get_dropdown_values("SELECT f.id_facility as k, CONCAT(f.facilitySN,' / ',p.facilityPN,' / ', t.typeName) as v FROM facility f INNER JOIN facilityPartNumber p ON f.id_f
$col_detail_5["editoptions"] = array("value"=>$str);
$col_detail_5["stype"] = "select"; // enable dropdown search
$col_detail_5["searchoptions"] = array("value" => ":;".$str);
$col_detail_5["formatter"] = "select"; // display label, not value
$cols_detail_5[] = $col_detail_5;

Thank you for your kind help

best regards

Andreas

Abu Ghufran answered 11 years ago

I'll prepare a sample for you and then email you.
Ticket will remain open.

Abu Ghufran answered 11 years ago

Emailed you sample code along with latest build.

Andreas answered 11 years ago

Hello Abu,

please excuse the late response but I have been on vacation the last week.
I have installed the latest build you have sent and it is working now like
expected.

Thank you very much for your great support.

best regards

Andreas

Your Answer

7 + 15 =

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?