Pass a default value in ADD record form

QuestionsPass a default value in ADD record form
Jorge Delfin asked 8 years ago

how can i set a value from the Master into the detail grid whet adding a new record.
im triyinf with this but this does not work:

$col["title"] = "No_GUIA"; // caption of column
$col["name"] = "No_GUIA"; // field name, must be exactly same as with SQL prefix or db field
$col["editoptions"] = array("defaultValue" => $_GET["No_GUIA"]);
——————————————————————-
the rest of the code:
// refresh detail grid on master edit
$opt["edit_options"]["afterSubmit"] = "function(){ jQuery('#list2').trigger('reloadGrid', [{current:true}]); return [true,'']; jQuery('#list1').setSelection(jQuery('#list1').jqGrid('getGridParam','selrow')); }";

// select after add
$opt["add_options"]["afterComplete"] = "function (response, postdata) { r = JSON.parse(response.responseText); $('#list1').setSelection(r.id); }";

// extra params passed to detail grid, column name comma separated
$opt["subgridparams"] = "ID,No_GUIA";
$opt["multiselect"] = false;
$opt["export"] = array("filename"=>"my-file", "sheetname"=>"test", "format"=>"pdf");
$opt["export"]["range"] = "filtered";

$opt["sortname"] = 'FECHA_DE_VENCIMIENTO';
$opt["sortorder"] = "asc";
$grid->set_options($opt);
$grid->table = "guias_retrasadas";

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

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

// receive id, selected row of parent grid
$id = intval($_GET["rowid"]);
$No_GUIA = $_GET["No_GUIA"];
// for non-int fields as PK
// $id = (empty($_GET["rowid"])?0:$_GET["rowid"]);

$opt = array();
$opt["sortname"] = 'id'; // by default sort grid by this field
$opt["sortorder"] = "desc"; // ASC or DESC
$opt["datatype"] = "local"; // stop loading detail grid at start
$opt["height"] = ""; // autofit height of subgrid
$opt["caption"] = "Seguimiento"; // caption of grid
$opt["multiselect"] = true; // allow you to multi-select through checkboxes
$opt["reloadedit"] = true; // reload after inline edit
$opt["export"] = array("filename"=>"my-file", "sheetname"=>"test", "format"=>"pdf", "range"=>"filtered"); // export to excel parameters

// Check if master record is selected before detail addition
$opt["add_options"]["beforeInitData"] = "function(formid){ var selr = jQuery('#list1').jqGrid('getGridParam','selrow'); if (!selr) { alert('Please select master record first'); return false; } }";

// fill detail grid add dialog with master grid id
$opt["add_options"]["afterShowForm"] = 'function() { var selr = jQuery("#list1").jqGrid("getGridParam","selrow"); jQuery("#ID").val( selr ) }';

// 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 ); }";
$grid->set_options($opt);

// and use in sql for filteration

$grid->select_command = "SELECT ID, No_GUIA, FECHA, COMENTARIOS FROM guias_seguimiento WHERE No_GUIA = '$No_GUIA'";
// this db table will be used for add,edit,delete
$grid->table = "guias_seguimiento";

$col = array();
$col["title"] = "Id"; // caption of column
$col["name"] = "ID"; // field name, must be exactly same as with SQL prefix or db field
$col["width"] = "20";
$col["editable"] = true;
$cols[] = $col;

$col["title"] = "No_GUIA"; // caption of column
$col["name"] = "No_GUIA"; // field name, must be exactly same as with SQL prefix or db field
$col["editoptions"] = array("defaultValue" => $_GET["name"]);

$col["width"] = "20";
$col["editable"] = true;
$cols[] = $col;

$col["title"] = "FECHA"; // caption of column
$col["name"] = "FECHA"; // field name, must be exactly same as with SQL prefix or db field
$col["width"] = "20";
$col["editable"] = true;
$cols[] = $col;

$col["title"] = "COMENTARIOS"; // caption of column
$col["name"] = "COMENTARIOS"; // field name, must be exactly same as with SQL prefix or db field
$col["width"] = "20";
$col["editable"] = true;
$cols[] = $col;

$grid->set_columns($cols);

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

2 Answers
Abu Ghufran answered 8 years ago

To pass data from master grid, you need to set

$opt["detail_grid_id"] = "list2"; // e.g. iD of detail grid
$opt["subgridparams"] = "No_GUIA,Name"; // columns of master grid, passed to detail (case sensitive) $col["name"] property.
$grid->set_options($opt);

Jorge answered 8 years ago

// fill detail grid add dialog with master grid id
$opt["add_options"]["afterShowForm"] = "function() { var selr = jQuery('#list1').jqGrid('getGridParam','selrow'); var rd=jQuery('#list1').jqGrid('getCell', selr, 'No_GUIA'); jQuery('#No_GUIA').val(rd); jQuery('#ID').val( selr );}";

Your Answer

19 + 7 =

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?