master grid value for new detail record

Questionsmaster grid value for new detail record
Richard Kooijman asked 12 years ago

Hi, how can i have a selected master grid value (e.g. supplier id) available in detailed grid when creating a new record. It is possible to have this for edit existing recs, by using "default", but this is not working when adding a new record. Only the value from script start is available then.

5 Answers
Abu Ghufran answered 12 years ago

Step1: Pass mydata (column name) in subgridparams in master grid

$opt["subGrid"] = true;
$opt["subgridurl"] = "subgrid_detail.php";

$opt["subgridparams"] = "mydata"; // comma sep. fields. will be POSTED from parent grid to subgrid, can be fetching using $_POST in subgrid
$grid->set_options($opt);

Step2: Read passed data.

for extra params passed from parent (e.g. company), we need some persistent storage in session for ajax calls
if (!empty($_POST["mydata"]))
$_SESSION["mydata"] = $_POST['mydata'];
$mydata = $_SESSION['mydata'];

Step2: Use in columns defaultVal

$col["editoptions"] = array("size"=>20, "defaultValue"=>$mydata);

….

A little fix is also required in jqgrid_dist.php.

search "session_start();", and remove the IF condition above it.

Richard Kooijman answered 12 years ago

Hi, unfortunately this is not the solution for my problem and I'm also not using the subgrid (yet). The "id" ("defaultValue"=>$mydata) which I need in the detail grid is not updated when selecting another row in the master grid. It only updates on a full refresh.
Any other solution? What I need is a method where new records in the detail grid are connected (by MySQL table) to the selected row (id) in the master grid.
Thanks in advance for your suggestions! br. Richard

Abu Ghufran answered 12 years ago

Hello,

Please refer master-detail.php example. It do perhaps exactly what you are searching.

Clients (master grid)
Invoices (detail grid)

When ever an invoice is added, it is linked to selected client of master grid.

I'm emailing you too.

Richard Kooijman answered 12 years ago

Hello, thanks I got it working now, however not by using $_GET, but by using a $_SESSION value that holds the $_GET value. Next thing I noticed is that "on_update" event is not called when using the inline edit. I use the function to do a calculation on the fields when updated. Any way to have this function called for inline edit as well (by clicking the "save" button)?

Abu Ghufran answered 12 years ago

Yes, it is called on inline edit too.

Your Answer

14 + 5 =

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?