Getting Selected Row of Parent Grid

QuestionsGetting Selected Row of Parent Grid
Dave Cook asked 11 years ago

I'm trying to get the selected row of my parent grid for a master/detail. The code is:

…..
// master
$g = new jqgrid();

$grid["caption"] = "Manage Groups";
$grid["altRows"] = true;
$grid["detail_grid_id"] = "list2";
$g->set_options($grid);
$g->set_options($grid);

$g->set_actions(array(
"add"=>true, // allow/disallow add
"edit"=>true, // allow/disallow edit
"delete"=>true, // allow/disallow delete
"rowactions"=>true, // show/hide row wise edit/del/save option
"export_csv"=>false, // show/hide export to excel option
"autofilter" => true, // show/hide autofilter for search
"search" => "simple" // show single/multi field search condition (e.g. simple or advance)
)
);

// select query with FK_data as FK_id, e.g. login.username as login_id
$g->select_command = "SELECT GROUP_ID, GROUP_NAME, GROUP_STATUS, LOGIN.LOGIN_USERNAME as LOGIN_ID FROM GROUPS
INNER JOIN LOGIN on LOGIN.LOGIN_ID = GROUPS.LOGIN_ID";

// set groups table for CRUD operations
$g->table = "GROUPS";

// pass the formatted columns to grid
$g->set_columns($cols);

// render grid
$out = $g->render("list1");

//// End Master Grid ////

// detail grid
$g = new jqgrid();

$grid["sortname"] = 'UUID'; // by default sort grid by this field
$grid["sortorder"] = "desc"; // ASC or DESC
$grid["height"] = ""; // autofit height of subgrid
$grid["caption"] = "Contact Data"; // caption of grid
$grid["multiselect"] = false; // allow you to multi-select through checkboxes
$grid["altRows"] = true;
$grid["export"] = array("format"=>"csv", "filename"=>"members");
$g->set_options($grid);

$g->set_actions(array(
"add"=>true, // allow/disallow add
"edit"=>true, // allow/disallow edit
"delete"=>true, // allow/disallow delete
"rowactions"=>true, // show/hide row wise edit/del/save option
"export_csv"=>true, // show/hide export to csv option
"autofilter" => true, // show/hide autofilter for search
"search" => "simple" // show single/multi field search condition (e.g. simple or advance)
)
);

// receive id, selected row of parent grid
$id = intval($_GET["UUID"]);
// and use in sql for filteration
$g->select_command = "SELECT UUID, EMAIL, FNAME, LNAME, ADDRESS, CITY, STATE, ZIP, PHONE_NUM, PHONE_CELLPHONE FROM CONTACTS WHERE (UUID IN (SE
LECT CG_UUID FROM CONTACT_GROUP WHERE CG_GROUP_ID = $id))";
// this db table will be used for add,edit,delete
$g->table = "CONTACTS";
// generate grid output, with unique grid name as 'list1'
$out_detail = $g->render("list2");

//// End Detail Grid ////

…..

My detail query is actually a subquery so there's a mapper table between the GROUPS table and the CONTACTS table called CONTACT_GROUP. I need to obtain the GROUP_ID from my master grid (GROUPS table) and send it down to my detail grid query but I can't seem to get it to work. I think the issue is that there is no direct relationship between GROUPS and CONTACTS. Any help appreciated.

4 Answers
Abu Ghufran answered 11 years ago

The parent grid PK is passed as var 'rowid', so you have to use following instead of uuid in detail grid.

$id = intval($_GET["rowid"]);

Other code seems fine. let me know the results.
Thanks

Abu Ghufran answered 11 years ago

Please ignore the last message of thread.

For master – detail on same page … use following param to refer selected parent id.

$id = intval($_GET["id"]);

Gandharv answered 11 years ago

I have 3 Grid grid1,grid2 and grid3.
I have to fetch grid1-ID on both grid2 and grid3.
[this can be achieved by
$id = intval($_GET["rowid"]);

But again i want grid2->ID on grid3.

So, how to achieve this?

Abu Ghufran answered 11 years ago

@Gandharv, i've emailed you the possible solution.

Your Answer

8 + 14 =

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?