Master-Detail-Grid-Problems

QuestionsMaster-Detail-Grid-Problems
Alex asked 9 years ago

Hi,

my Detail-Grid the correct rows when I select a row in the Master-Grid,but as soon as I click on a row in the Detail-Grid all the rows in the Detail-Grid disapear.
My suspicion is that the Detail-Grid overrides the $id with the rowid of the selected row in the Detail-Grid. I don't know how to solve this problem though.

Here is my code.

Master-Grid:
<?php
// include db config
include_once("config.php");

// set up DB
mysql_connect(PHPGRID_DBHOST, PHPGRID_DBUSER, PHPGRID_DBPASS);
mysql_select_db(PHPGRID_DBNAME);

// include and create object
include(PHPGRID_LIBPATH . "inc/jqgrid_dist.php");
$buchungsgruppen = new jqgrid();

// set few params
$grid["caption"] = "Buchungsgruppen";
$grid["autowidth"] = true; // expand grid to screen width
$grid["multiselect"] = false;

$grid["export"] = array("filename" => "Buchungsgruppen", "heading" => "Buchungsgruppen", "orientation" => "portrait", "paper" => "a4");
// for excel, sheet header
$grid["export"]["sheetname"] = "Buchungsgruppen";

// export filtered data or all data
$grid["export"]["range"] = "filtered"; // or "all"

$grid["detail_grid_id"] = "list2";

$buchungsgruppen->set_options($grid);

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

// set database table for CRUD operations
$buchungsgruppen->table = "buchungsgruppen";

$buchungsgruppen->select_command = "SELECT buchungsgruppen.ID, Name, Beschreibung,
SUM(Betrag) as Summe
FROM buchungen INNER JOIN buchungsgruppen ON buchungen.BGruppe_ID = buchungsgruppen.ID
GROUP BY buchungsgruppen.ID, Name, Beschreibung";

$buchungsgruppen->set_conditional_css($f_conditions);
//</editor-fold>
// render grid
$out_buchungsgruppen = $buchungsgruppen->render("list1");
?>

Detail-Grid:
<?php
$buchungen_detail = new jqgrid();

$grid["caption"] = "Buchungen";
$grid["sortname"] = 'Datum';
$grid["sortorder"] = "desc";
$grid["autowidth"] = true; // expand grid to screen width
$grid["multiselect"] = false;

$buchungen_detail->set_options($grid);
$id = intval($_GET["rowid"]);

$buchungen_detail->table = "buchungen";

$buchungen_detail->select_command = "SELECT `buchungen`.`ID`, Datum, Betrag,
Verwendungszweck, Art,
konten.IBAN AS Konto, buchungsgruppen.Name as Buchungsgruppe
FROM buchungen INNER JOIN buchungsgruppen ON buchungen.BGruppe_ID = buchungsgruppen.ID
INNER JOIN konten ON buchungen.Konto_ID = konten.ID
WHERE buchungen.BGruppe_ID = $id";

$buchungen_detail->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
"export_excel" => false, // export excel button
"export_pdf" => false, // export pdf button
"autofilter" => false, // show/hide autofilter for search
"search" => "advance" // show single/multi field search condition (e.g. simple or advance)
)
);

$out_buchungen_detail = $buchungen_detail->render("list2");
?>

2 Answers
Abu Ghufran answered 9 years ago

Whenever you select a row in master grid, it send an ajax call passing the master row id in url, and loads the detail grid data.

As you have mentioned it is set in $id and detail grid sql command, so it will be loading the detail grid rows that have corresponding BGruppe_ID. Blank result could mean that there is nothing in database with such condition.

When you don't select any row in master, it is showing all records with BGruppe_ID = 0 as you have used intval() function in getting rowid of master.

Alex answered 9 years ago

Hey Abu,

thanks for the fast answer.

The problem was that I specified the
$grid["detail_grid_id"] = "list2";
statement in the Master-Grid and also used the $grid variable in the Detail-Grid.
So the Detail-Grid also got the command to connect to a Detail-Grid called "list2"(itsself) so it refreshed itself when I clicked on a row.

Cheers
Alex

Your Answer

9 + 18 =

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?