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!
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, ''];
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);
Rectify:
function fnRefreshTotalValuesInvoice(&$data)
{
$id = intval($_GET["rowid"]);
//[..]
// mysql_query updating total values in Invoice
//[..]
}
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
I have a master detail grid.
Master grid –> Invoice header data (date, client, total values)
Detail Grid –> Invoice lines (description, quantity, price, tax….)
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
Hi, Abu!
I'm doing something wrong….
Screen capt:
[IMG]http://i59.tinypic.com/2m2hz5j.jpg[/IMG]
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.
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);