Master refresh on subgrid update

QuestionsMaster refresh on subgrid update
Alberto asked 10 years ago

Hi!

I've a master and a detail grid (subgrid). When I change detail grid (add/edit or delete), I refresh parent grid using:

$detailopt["add_options"]["afterSubmit"] = "function(){jQuery('#list1').trigger('reloadGrid',[{current:true}]); return [true, ''];}";
$detailopt["edit_options"]["afterSubmit"] = "function(){jQuery('#list1').trigger('reloadGrid',[{current:true}]); return [true, ''];}";
$detailopt["delete_options"]["afterSubmit"] = "function() jQuery('#list1').trigger('reloadGrid',[{current:true}]); return [true, ''];}";
$detailgrid->set_options($detailopt);

The parent is ok, the row that I've been modifying is selected, but subgrid is "frozen". It shows the detail, but add/edit/delete buttons are inactive.

Thanks!

10 Answers
Abu Ghufran answered 10 years ago

Try adding these lines.

Get parent selected row, reload, make parent row selection.

var selr = jQuery('#list1').jqGrid('getGridParam','selrow');
jQuery('#list1').trigger('reloadGrid',[{current:true}]);
jQuery('#list1').jqGrid('setSelection',selr,true);
return [true, ''];

Alberto answered 10 years ago

Hi!

It doesn't works. The result is the same. It reloads parent grid, parent row is selected but add/edit/delete buttons in detail grid are inaccessible.

In detail grid events (Invoice detail):

$e["on_insert"] = array("add_det_invoice", null, true);
$e["on_after_insert"] = array("fnRefreshTotalValuesInvoice",null, false);
$e["on_after_update"] = array("fnRefreshTotalValuesInvoice",null, false);
$e["on_after_delete"] = array("fnRefreshTotalValuesInvoice",null, false);
$detailgrid->set_events($e);

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

function fnActualizaVenta(&$data)
{
$id = intval($_GET["rowid"]);
//[..]
// mysql_query updating total values in Invoice
//[..]
}

In detail grid options:

$detailopt["add_options"]["afterSubmit"] = "function(){var selr = jQuery('#list1').jqGrid('getGridParam','selrow'); jQuery('#list1').trigger('reloadGrid',[{current:true}]); jQuery('#list1').jqGrid('setSelection',selr,true); return [true, ''];}";
$detailopt["edit_options"]["afterSubmit"] = "function(){var selr = jQuery('#list1').jqGrid('getGridParam','selrow'); jQuery('#list1').trigger('reloadGrid',[{current:true}]); jQuery('#list1').jqGrid('setSelection',selr,true); return [true, ''];}";
$detailopt["delete_options"]["afterSubmit"] = "function(){var selr = jQuery('#list1').jqGrid('getGridParam','selrow'); jQuery('#list1').trigger('reloadGrid',[{current:true}]); jQuery('#list1').jqGrid('setSelection',selr,true); return [true, ''];}";
$detailgrid->set_options($detailopt);

Alberto answered 10 years ago

Rectify:

function fnRefreshTotalValuesInvoice(&$data)
{
$id = intval($_GET["rowid"]);
//[..]
// mysql_query updating total values in Invoice
//[..]
}

Abu Ghufran answered 10 years ago

If you are using subgrid, you can simple enable auto-expand last opened subgrid on refresh.

add persist settings include files and jscode
http://hastebin.com/yatavukuxo.html

And in detail code, connect aftersave and aftersubmit events to reload parent.

// reload parent on update
$grid["onAfterSave"] = "function(){ jQuery('#list1').trigger('reloadGrid',[{jqgrid_page:1}]); }";
// reload parent on add
$grid["add_options"]["afterSubmit"] = "function(){jQuery('#list1').trigger('reloadGrid',[{jqgrid_page:1}]); return [true, ''];}";

Complete code here … you can replace in demos/master-detail folder and check.

Subgrid code: http://phpgrid.org/demo/demos/master-detail/subgrid.phps
Detail code: http://phpgrid.org/demo/demos/master-detail/subgrid_detail.phps

Alberto answered 10 years ago

I have a master detail grid.
Master grid –> Invoice header data (date, client, total values)
Detail Grid –> Invoice lines (description, quantity, price, tax….)

http://hastebin.com/tujoqaqubu.php

Abu Ghufran answered 10 years ago

Put the last selection call in setTimeout function. All rest seems fine.

// reload master after detail update
$opt["onAfterSave"] = "function(){ var selr = jQuery('#list1').jqGrid('getGridParam','selrow'); jQuery('#list1').trigger('reloadGrid',[{jqgrid_page:1}]); setTimeout( function(){jQuery('#list1').setSelection(selr,true);},500 ); }";

Demo: http://phpgrid.org/demo/demos/master-detail/master-detail.php
Code: http://phpgrid.org/demo/demos/master-detail/master-detail.phps

Alberto answered 10 years ago

Hi, Abu!

I'm doing something wrong….

Screen capt:
[IMG]http://i59.tinypic.com/2m2hz5j.jpg[/IMG]

Code:
http://pastebin.com/HmNQUSjB

Alberto answered 10 years ago

Abu, in your code, when a detail line in grid is modified or added, if you select another line (in master or detail) and edit or adds a new one, edit form shows the data of the line edited/added before.

Alberto answered 10 years ago

I have it!

In detail grid options:

$detailopt["add_options"]["afterSubmit"] = "function(){ var selr = jQuery('#list1').jqGrid('getGridParam','selrow'); jQuery('#list1').trigger('reloadGrid',[{jqgrid_page:1}]); setTimeout( function(){jQuery('#list1').setSelection(selr,true);},500 ); return [true, ''];}";
$detailopt["edit_options"]["afterSubmit"] = "function(){ var selr = jQuery('#list1').jqGrid('getGridParam','selrow'); jQuery('#list1').trigger('reloadGrid',[{jqgrid_page:1}]); setTimeout( function(){jQuery('#list1').setSelection(selr,true);},500 ); return [true, ''];}";
$detailopt["delete_options"]["afterSubmit"] = "function(){ var selr = jQuery('#list1').jqGrid('getGridParam','selrow'); jQuery('#list1').trigger('reloadGrid',[{jqgrid_page:1}]); setTimeout( function(){jQuery('#list1').setSelection(selr,true);},500 ); return [true, ''];}";

//$detailopt["onAfterSave"] = "function(){ var selr = jQuery('#list1').jqGrid('getGridParam','selrow'); jQuery('#list1').trigger('reloadGrid',[{jqgrid_page:1}]); setTimeout( function(){jQuery('#list1').setSelection(selr,true);},500 ); }";
$detailgrid->set_options($detailopt);

Abu Ghufran answered 10 years ago

If you are using dialog based editing, afterSubmit event will work.
In case of inline editing, onAfterSave will be required.

Glad to know it's resolved.

Your Answer

3 + 4 =

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?