nested-master-detail only get $id = intval($_GET["rowid"]); but not other grid field

Questionsnested-master-detail only get $id = intval($_GET["rowid"]); but not other grid field
Alejandro Morales asked 9 years ago

Hello Abu,

When I try to Get a field other than Id don`t work. (nested-master-detail.php sample)

This is the code:

——————————-
// detail detail grid
$grid = new jqgrid();
$opt = array();
$opt["sortname"] = 'id'; // by default sort grid by this field
$opt["sortorder"] = "desc"; // ASC or DESC
$opt["height"] = ""; // autofit height of subgrid
$opt["caption"] = "Events Information"; // caption of grid

$opt["autowidth"] = true; // expand grid to screen width
$opt["subgridparams"] = "Id,Event,Year,StartDate,EndDate,Description";

$grid->set_options($opt);

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

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

// Trying to get the Event
$event = intval($_GET["Event"]); // DON'T WORK

$grid->select_command = "SELECT Id,Event,Year,StartDate,EndDate,Description FROM events WHERE Id = $event";
$grid->table = "events";
$out_detail_detail = $grid->render("list3");

Thanks and regards.

4 Answers
Abu Ghufran answered 9 years ago

Hi,

Please re-check that $col['name'] can be used in subgridparams. (case sensitive)
$opt["subgridparams"] = "Id,Event,Year,StartDate,EndDate,Description";

For any issue, please compare with working demo.
If problem do not solve, send me complete code for review.

Alejandro Morales answered 9 years ago

Hello Abu,

I compare with working demo and don`t work. Working demo don`t use $opt["subgridparams"]. I erased the line: $opt["subgridparams"] = "Id,Event,Year,StartDate,EndDate,Description";

Event field on database is named Event (case sensitive). I'm working with three tables but demos works with two tables only.

Complete code is:

——————————————

// master grid
$grid = new jqgrid();
$opt["caption"] = "Companies Information";
$opt["height"] = "200";
$opt["autowidth"] = true; // expand grid to screen width

// following params will enable subgrid — by default first column (PK) of parent is passed as param 'id'
$opt["detail_grid_id"] = "list2";
$grid->set_options($opt);
$grid->set_options($opt);
$grid->table = "companies";

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

$out_master = $grid->render("list1");

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

$opt = array();
$opt["sortname"] = 'id'; // by default sort grid by this field
$opt["sortorder"] = "desc"; // ASC or DESC
$opt["height"] = ""; // autofit height of subgrid
$opt["caption"] = "Participants Information"; // caption of grid
$opt["export"] = array("filename"=>"my-file", "sheetname"=>"test"); // export to excel parameters
$opt["autowidth"] = true; // expand grid to screen width
$opt["detail_grid_id"] = "list3";
$grid->set_options($opt);

$grid->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"=>true, // show/hide export to excel option
"autofilter" => true, // show/hide autofilter for search
"search" => "advance" // show single/multi field search condition (e.g. simple or advance)
)
);

// receive id, selected row of parent grid
$id = intval($_GET["rowid"]);
// and use in sql for filteration
//$grid->select_command = "SELECT id,client_id,invdate,amount,tax,total FROM invheader WHERE client_id = $id";

$grid->select_command = "SELECT Id,Company,FirstName,LastName,Title,Phone,CellPhone,Email,Event FROM participantes WHERE Company = $id";

// this db table will be used for add,edit,delete
$grid->table = "participantes";

$e["on_insert"] = array("add_client", null, true);
$grid->set_events($e);

function add_client(&$data)
{
$id = intval($_GET["rowid"]);
$data["params"]["Event"] = $id;
}

// generate grid output, with unique grid name as 'list1'
$out_detail = $grid->render("list2");

// detail detail grid
$grid = new jqgrid();
$opt = array();
$opt["sortname"] = 'id'; // by default sort grid by this field
$opt["sortorder"] = "desc"; // ASC or DESC
$opt["height"] = ""; // autofit height of subgrid
$opt["caption"] = "Events Information"; // caption of grid

$opt["autowidth"] = true; // expand grid to screen width

$grid->set_options($opt);

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

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

// Trying to get Event
$theevent = intval($_GET["Event"]); // Don`t work

$grid->select_command = "SELECT Id,Event,Year,StartDate,EndDate,Description FROM events WHERE Id = $theevent";
$grid->table = "events";
$out_detail_detail = $grid->render("list3");

—————————————–

Thanks again Abu and best regards.

Abu Ghufran answered 9 years ago

You can only use fields in subgridparams that are present in grid column data. And on clicking that grid row, it will be passed to the child grid.

If you use following in detail grid, it wont work as it only have Event field.
$opt["subgridparams"] = "Id,Event,Year,StartDate,EndDate,Description";

Instead you can only set:
$opt["subgridparams"] = "Event";

Hope it help.

Alejandro Morales answered 9 years ago

Thank you Abu.

Now wordks fine.

Thanks for all your support.

Great job!

Your Answer

4 + 9 =

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?