Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * PHP Grid Component
- *
- * @author Abu Ghufran <gridphp@gmail.com> - http://www.phpgrid.org
- * @version 2.0.0
- * @license: see license.txt included in package
- */
- include("../lib/php/conexion_total.php");
- include("../phpgrid-full-v2.0/lib/inc/jqgrid_dist.php");
- $grid = new jqgrid($db_conf);
- $grid->table = "donantes";
- $opt["caption"] = "donantes Data";
- $opt["height"] = "150";
- // id beneficiario
- $col = array();
- $col["title"] = "id_don"; // caption of column
- $col["name"] = "id_don";
- $col["width"] = "50";
- $col["hidden"] = true;
- $col["sortable"] = true; // this column is not sortable
- $col["search"] = true; // this column is not searchable
- $col["editable"] =true;
- $col["export"] = true; // this column will not be exported
- $cols[] = $col;
- // id beneficiario
- $col = array();
- $col["title"] = "nombre"; // caption of column
- $col["name"] = "nombre";
- $col["width"] = "50";
- $col["hidden"] = false;
- $col["sortable"] = true; // this column is not sortable
- $col["search"] = true; // this column is not searchable
- $col["editable"] =false;
- $col["export"] = true; // this column will not be exported
- $cols[] = $col;
- // id beneficiario
- $col = array();
- $col["title"] = "apellidos"; // caption of column
- $col["name"] = "apellidos";
- $col["width"] = "100";
- $col["hidden"] = false;
- $col["sortable"] = true; // this column is not sortable
- $col["search"] = true; // this column is not searchable
- $col["editable"] =false;
- $col["export"] = true; // this column will not be exported
- $cols[] = $col;
- //codigo
- $col = array();
- $col["title"] = "tipo_donacion"; // caption of column
- $col["name"] = "tipo_donacion";
- $col["width"] = "40";
- $col["hidden"] = false;
- $col["sortable"] = true; // this column is not sortable
- $col["search"] = true; // this column is not searchable
- $col["editable"] =false;
- $col["export"] = true; // this column will not be exported
- $cols[] = $col;
- $col = array();
- $col["title"] = "importe";
- $col["name"] = "donacion";
- $col["width"] = "50"; // not specifying width will expand to fill space
- $col["align"] = "right"; // this column is not editable
- $col["sortable"] = true; // this column is not sortable
- $col["search"] = true; // this column is not searchable
- //$col["linkoptions"] = "target='_blank'"; // extra params with <a> tag
- $col["editable"] = false;
- $col["export"] = true; // this column will not be exported
- $cols[] = $col;
- $col = array();
- $col["title"] = "incidencia";
- $col["name"] = "detail";
- $col["default"] = "<a class='fancybox' onclick='jQuery(\"#list1\").setSelection({id_don});' href='#box_detail_grid' stylt='width: 500px'>incidencia</a>";
- $col["width"] = "40";
- $col["editable"] = true;
- $col["search"] = false;
- $col["export"] = false;
- $cols[] = $col;
- // identificador beneficiario
- $col = array();
- $col["title"] = "identificador"; // caption of column
- $col["name"] = "identificador";
- $col["width"] = "40";
- $col["hidden"] = false;
- $col["sortable"] = true; // this column is not sortable
- $col["search"] = true; // this column is not searchable
- $col["editable"] =false;
- $col["export"] = true; // this column will not be exported
- $col["link"] = "./f_ver_listas.php?id_don={id_don}";
- $col["linkoptions"] = "target='_blank'"; // extra params with <a> tag
- $cols[] = $col;
- $grid->set_columns($cols);
- // following params will enable subgrid -- by default first column (PK) of parent is passed as param 'id'
- $opt["detail_grid_id"] = "list2";
- // 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 nombre comma separated
- $opt["subgridparams"] = "id_don,gender,company";
- $opt["multiselect"] = false;
- $opt["export"] = array("filename"=>"my-file", "sheetname"=>"test", "format"=>"xls");
- $opt["export"]["range"] = "filtered";
- $grid->set_options($opt);
- $grid->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"=>true, // show/hide export to excel option
- "autofilter" => true, // show/hide autofilter for search
- "search" => "advance" // show single/multi field search condition (e.g. simple or advance)
- )
- );
- $out_master = $grid->render("list1");
- // detail grid
- $grid_2 = new jqgrid($db_conf);
- $grid_2->table = "incidencias";
- $opt_2 = array();
- $opt_2["sortname"] = 'id_incid'; // by default sort grid by this field
- $opt_2["sortorder"] = "desc"; // ASC or DESC
- $opt_2["datatype"] = "local"; // stop loading detail grid at start
- $opt_2["height"] = ""; // autofit height of subgrid
- $opt_2["caption"] = "Invoice Data"; // caption of grid
- $opt_2["multiselect"] = true; // allow you to multi-select through checkboxes
- $opt_2["reloadedit"] = true; // reload after inline edit
- $opt_2["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_2["add_options"]["beforeInitData"] = "function(formid){ var selr = jQuery('#list1').jqGrid('getGridParam','selrow'); if (!selr) { alert('Please select master record first'); return false; } }";
- // reload master after detail update
- $opt_2["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_2->set_options($opt_2);
- // receive id, selected row of parent grid
- $id = intval($_GET["rowid"]);
- $nombre = $_GET["nombre"];
- $cid = intval($_GET["id_don"]);;
- // for non-int fields as PK
- // $id = (empty($_GET["rowid"])?0:$_GET["rowid"]);
- $grid_2->select_command = "SELECT id_incid, id_don, codigo, incidencia, fecha, fecha_cierre, '$nombre' as 'nombre', '$apellidos' as 'apellidos' FROM incidencias WHERE id_don= $cid";
- $col_2 = array();
- $col_2["title"] = "id_don"; // caption of column
- $col_2["name"] = "id_don"; // field name, must be exactly same as with SQL prefix or db field
- $col_2["editable"] = false;
- $col_2["width"] = "10";
- $col_2["hidden"] = true;
- $col_2s[] = $col_2;
- /*
- $col_2 = array();
- $col_2["title"] = "Client";
- $col_2["name"] = "id_don";
- $col_2["width"] = "100";
- $col_2["align"] = "left";
- $col_2["search"] = true;
- $col_2["editable"] = true;
- $col_2["edittype"] = "select";
- $col_2["formatter"] = "select";
- $str = $grid->get_dropdown_values("select distinct id_don as k, nombre as v from donantes");
- $col_2["editoptions"] = array("value"=>":;".$str);
- $col_2["editoptions"]["onload"]["sql"] = "select distinct id_don as k, nombre as v from donantes";
- $col_2["editoptions"]["onchange"]["sql"] = "select note as k, note as v from incidencias WHERE id_don = '{id_don}'";
- $col_2["editoptions"]["onchange"]["update_field"] = "note";
- $col_2s[] = $col_2;
- */
- $col_2 = array();
- $col_2["title"] = "id_incid";
- $col_2["name"] = "id_incid";
- $col_2["width"] = "10";
- $col_2["editable"] = false;
- //set detail form client_id as readonly and for add dialog only
- //$col_2["editoptions"] = array("readonly"=>"readonly", "style"=>"border:0");
- $col_2["hidden"] = true;
- $col_2s[] = $col_2;
- $col_2 = array();
- $col_2["title"] = "nombre";
- $col_2["name"] = "nombre";
- $col_2["width"] = "40'";
- $col_2["editable"] = false;
- //set detail form client_id as readonly and for add dialog only
- //$col_2["editoptions"] = array("readonly"=>"readonly", "style"=>"border:0");
- $col_2["show"]["edit"] = false;
- $col_2s[] = $col_2;
- $col_2 = array();
- $col_2["title"] = "apellidos";
- $col_2["name"] = "apellidos";
- $col_2["width"] = "50'";
- $col_2["editable"] = false;
- //set detail form client_id as readonly and for add dialog only
- //$col_2["editoptions"] = array("readonly"=>"readonly", "style"=>"border:0");
- $col_2["show"]["edit"] = false;
- $col_2s[] = $col_2;
- $col_2 = array();
- $col_2["title"] = "fecha";
- $col_2["name"] = "fecha";
- $col_2["width"] = "15";
- $col_2["editable"] = true; // this column is editable
- # format as date
- $col_2["formatter"] = "date";
- # opts array can have these options: http://api.jqueryui.com/datepicker/
- $col_2["formatoptions"] = array("srcformat"=>'Y-m-d',"newformat"=>'d-m-Y', "opts" => array("changeYear" => true, "dateFormat"=>'yy-mm-dd', "minDate"=>"15-07-08"));
- $col_2s[] = $col_2;
- $col_2 = array();
- $col_2["title"] = "incidencia";
- $col_2["name"] = "incidencia";
- $col_2["width"] = "100";
- $col_2["editable"] = true; // this column is editable
- $col_2["edittype"] = "textarea"; // render as textarea on edit
- $col_2["editoptions"] = array("rows"=>20, "cols"=>32); // with these attributes
- $col_2s[] = $col_2;
- $grid_2->set_columns($col_2s);
- $grid_2->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)
- )
- );
- $e["on_insert"] = array("add_incidencia", null, true);
- $e["on_update"] = array("update_incidencia", null, true);
- $grid_2->set_events($e);
- function add_incidencia(&$data)
- {
- $id = intval($_GET["rowid"]);
- $data["params"]["id_don"] = $id;
- //$data["params"]["total"] = $data["params"]["amount"] + $data["params"]["tax"];
- }
- function update_incidencia(&$data)
- {
- $id = intval($_GET["rowid"]);
- $data["params"]["id_don"] = $id;
- }
- // generate grid output, with unique grid nombre as 'list1'
- $out_detail = $grid_2->render("list2");
- ?>
- <!doctype html>
- <html>
- <head>
- <meta charset="utf-8">
- <link rel="stylesheet" type="text/css" href="../phpgrid-full-v2.0/lib/js/themes/flick/jquery-ui.custom.css">
- <link rel="stylesheet" type="text/css" href="../phpgrid-full-v2.0/lib/js/jqgrid/css/ui.jqgrid.css">
- <script src="../phpgrid-full-v2.0/lib/js/jquery.min.js"></script>
- <script src="../phpgrid-full-v2.0/lib/js/jqgrid/js/i18n/grid.locale-en.js"></script>
- <script src="../phpgrid-full-v2.0/lib/js/jqgrid/js/i18n/grid.locale-es.js"></script>
- <script src="../phpgrid-full-v2.0/lib/js/jqgrid/js/jquery.jqGrid.min.js"></script>
- <script src="../phpgrid-full-v2.0/lib/js/themes/jquery-ui.custom.min.js"></script></script>
- <!-- Add fancyBox main JS and CSS files -->
- <link type="text/css" rel="stylesheet" href="//cdn.jsdelivr.net/fancybox/2.1.4/jquery.fancybox.css" />
- <script type="text/javascript" src="//cdn.jsdelivr.net/fancybox/2.1.4/jquery.fancybox.js"></script>
- </head>
- <body>
- <div style="margin:10px">
- Master Detail Grid, on same page
- <br>
- <br>
- <?php echo $out_master ?>
- <br>
- <?php echo $out_detail; ?>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement