Advertisement
fsnoya

master-detail

Oct 26th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.41 KB | None | 0 0
  1. <?php
  2. /**
  3. * PHP Grid Component
  4. *
  5. * @author Abu Ghufran <gridphp@gmail.com> - http://www.phpgrid.org
  6. * @version 2.0.0
  7. * @license: see license.txt included in package
  8. */
  9.  
  10. include("../lib/php/conexion_total.php");
  11.  
  12. include("../phpgrid-full-v2.0/lib/inc/jqgrid_dist.php");
  13.  
  14.  
  15. $grid = new jqgrid($db_conf);
  16.  
  17. $grid->table = "donantes";
  18.  
  19. $opt["caption"] = "donantes Data";
  20. $opt["height"] = "150";
  21.  
  22. // id beneficiario
  23. $col = array();
  24. $col["title"] = "id_don"; // caption of column
  25. $col["name"] = "id_don";
  26. $col["width"] = "50";
  27. $col["hidden"] = true;
  28. $col["sortable"] = true; // this column is not sortable
  29. $col["search"] = true; // this column is not searchable
  30. $col["editable"] =true;
  31. $col["export"] = true; // this column will not be exported
  32. $cols[] = $col;
  33.  
  34.  
  35. // id beneficiario
  36. $col = array();
  37. $col["title"] = "nombre"; // caption of column
  38. $col["name"] = "nombre";
  39. $col["width"] = "50";
  40. $col["hidden"] = false;
  41. $col["sortable"] = true; // this column is not sortable
  42. $col["search"] = true; // this column is not searchable
  43. $col["editable"] =false;
  44. $col["export"] = true; // this column will not be exported
  45. $cols[] = $col;
  46.  
  47. // id beneficiario
  48. $col = array();
  49. $col["title"] = "apellidos"; // caption of column
  50. $col["name"] = "apellidos";
  51. $col["width"] = "100";
  52. $col["hidden"] = false;
  53. $col["sortable"] = true; // this column is not sortable
  54. $col["search"] = true; // this column is not searchable
  55. $col["editable"] =false;
  56. $col["export"] = true; // this column will not be exported
  57. $cols[] = $col;
  58.  
  59. //codigo
  60. $col = array();
  61. $col["title"] = "tipo_donacion"; // caption of column
  62. $col["name"] = "tipo_donacion";
  63. $col["width"] = "40";
  64. $col["hidden"] = false;
  65. $col["sortable"] = true; // this column is not sortable
  66. $col["search"] = true; // this column is not searchable
  67. $col["editable"] =false;
  68. $col["export"] = true; // this column will not be exported
  69. $cols[] = $col;
  70.  
  71. $col = array();
  72. $col["title"] = "importe";
  73. $col["name"] = "donacion";
  74. $col["width"] = "50"; // not specifying width will expand to fill space
  75. $col["align"] = "right"; // this column is not editable
  76. $col["sortable"] = true; // this column is not sortable
  77. $col["search"] = true; // this column is not searchable
  78. //$col["linkoptions"] = "target='_blank'"; // extra params with <a> tag
  79. $col["editable"] = false;
  80. $col["export"] = true; // this column will not be exported
  81. $cols[] = $col;
  82.  
  83. $col = array();
  84. $col["title"] = "incidencia";
  85. $col["name"] = "detail";
  86. $col["default"] = "<a class='fancybox' onclick='jQuery(\"#list1\").setSelection({id_don});' href='#box_detail_grid' stylt='width: 500px'>incidencia</a>";
  87. $col["width"] = "40";
  88. $col["editable"] = true;
  89. $col["search"] = false;
  90. $col["export"] = false;
  91. $cols[] = $col;
  92.  
  93.  
  94. // identificador beneficiario
  95. $col = array();
  96. $col["title"] = "identificador"; // caption of column
  97. $col["name"] = "identificador";
  98. $col["width"] = "40";
  99. $col["hidden"] = false;
  100. $col["sortable"] = true; // this column is not sortable
  101. $col["search"] = true; // this column is not searchable
  102. $col["editable"] =false;
  103. $col["export"] = true; // this column will not be exported
  104. $col["link"] = "./f_ver_listas.php?id_don={id_don}";
  105. $col["linkoptions"] = "target='_blank'"; // extra params with <a> tag
  106. $cols[] = $col;
  107.  
  108.  
  109. $grid->set_columns($cols);
  110.  
  111. // following params will enable subgrid -- by default first column (PK) of parent is passed as param 'id'
  112. $opt["detail_grid_id"] = "list2";
  113.  
  114. // refresh detail grid on master edit
  115. $opt["edit_options"]["afterSubmit"] = "function(){ jQuery('#list2').trigger('reloadGrid', [{current:true}]); return [true,'']; jQuery('#list1').setSelection(jQuery('#list1').jqGrid('getGridParam','selrow')); }";
  116.  
  117. // select after add
  118. $opt["add_options"]["afterComplete"] = "function (response, postdata) { r = JSON.parse(response.responseText); $('#list1').setSelection(r.id); }";
  119.  
  120. // extra params passed to detail grid, column nombre comma separated
  121. $opt["subgridparams"] = "id_don,gender,company";
  122. $opt["multiselect"] = false;
  123. $opt["export"] = array("filename"=>"my-file", "sheetname"=>"test", "format"=>"xls");
  124. $opt["export"]["range"] = "filtered";
  125. $grid->set_options($opt);
  126.  
  127.  
  128.  
  129. $grid->set_actions(array(
  130. "add"=>false, // allow/disallow add
  131. "edit"=>false, // allow/disallow edit
  132. "delete"=>false, // allow/disallow delete
  133. "rowactions"=>false, // show/hide row wise edit/del/save option
  134. "export"=>true, // show/hide export to excel option
  135. "autofilter" => true, // show/hide autofilter for search
  136. "search" => "advance" // show single/multi field search condition (e.g. simple or advance)
  137. )
  138. );
  139.  
  140. $out_master = $grid->render("list1");
  141.  
  142. // detail grid
  143. $grid_2 = new jqgrid($db_conf);
  144. $grid_2->table = "incidencias";
  145.  
  146. $opt_2 = array();
  147. $opt_2["sortname"] = 'id_incid'; // by default sort grid by this field
  148. $opt_2["sortorder"] = "desc"; // ASC or DESC
  149. $opt_2["datatype"] = "local"; // stop loading detail grid at start
  150. $opt_2["height"] = ""; // autofit height of subgrid
  151. $opt_2["caption"] = "Invoice Data"; // caption of grid
  152. $opt_2["multiselect"] = true; // allow you to multi-select through checkboxes
  153. $opt_2["reloadedit"] = true; // reload after inline edit
  154. $opt_2["export"] = array("filename"=>"my-file", "sheetname"=>"test", "format"=>"pdf", "range"=>"filtered"); // export to excel parameters
  155.  
  156. // Check if master record is selected before detail addition
  157. // $opt_2["add_options"]["beforeInitData"] = "function(formid){ var selr = jQuery('#list1').jqGrid('getGridParam','selrow'); if (!selr) { alert('Please select master record first'); return false; } }";
  158.  
  159. // reload master after detail update
  160. $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 ); }";
  161. $grid_2->set_options($opt_2);
  162.  
  163. // receive id, selected row of parent grid
  164. $id = intval($_GET["rowid"]);
  165. $nombre = $_GET["nombre"];
  166. $cid = intval($_GET["id_don"]);;
  167.  
  168. // for non-int fields as PK
  169. // $id = (empty($_GET["rowid"])?0:$_GET["rowid"]);
  170.  
  171. $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";
  172.  
  173.  
  174.  
  175.  
  176. $col_2 = array();
  177. $col_2["title"] = "id_don"; // caption of column
  178. $col_2["name"] = "id_don"; // field name, must be exactly same as with SQL prefix or db field
  179. $col_2["editable"] = false;
  180. $col_2["width"] = "10";
  181. $col_2["hidden"] = true;
  182. $col_2s[] = $col_2;
  183.  
  184. /*
  185. $col_2 = array();
  186. $col_2["title"] = "Client";
  187. $col_2["name"] = "id_don";
  188. $col_2["width"] = "100";
  189. $col_2["align"] = "left";
  190. $col_2["search"] = true;
  191. $col_2["editable"] = true;
  192. $col_2["edittype"] = "select";
  193. $col_2["formatter"] = "select";
  194. $str = $grid->get_dropdown_values("select distinct id_don as k, nombre as v from donantes");
  195. $col_2["editoptions"] = array("value"=>":;".$str);
  196. $col_2["editoptions"]["onload"]["sql"] = "select distinct id_don as k, nombre as v from donantes";
  197. $col_2["editoptions"]["onchange"]["sql"] = "select note as k, note as v from incidencias WHERE id_don = '{id_don}'";
  198. $col_2["editoptions"]["onchange"]["update_field"] = "note";
  199. $col_2s[] = $col_2;
  200. */
  201.  
  202. $col_2 = array();
  203. $col_2["title"] = "id_incid";
  204. $col_2["name"] = "id_incid";
  205. $col_2["width"] = "10";
  206. $col_2["editable"] = false;
  207. //set detail form client_id as readonly and for add dialog only
  208. //$col_2["editoptions"] = array("readonly"=>"readonly", "style"=>"border:0");
  209. $col_2["hidden"] = true;
  210. $col_2s[] = $col_2;
  211.  
  212. $col_2 = array();
  213. $col_2["title"] = "nombre";
  214. $col_2["name"] = "nombre";
  215. $col_2["width"] = "40'";
  216. $col_2["editable"] = false;
  217. //set detail form client_id as readonly and for add dialog only
  218. //$col_2["editoptions"] = array("readonly"=>"readonly", "style"=>"border:0");
  219. $col_2["show"]["edit"] = false;
  220. $col_2s[] = $col_2;
  221.  
  222. $col_2 = array();
  223. $col_2["title"] = "apellidos";
  224. $col_2["name"] = "apellidos";
  225. $col_2["width"] = "50'";
  226. $col_2["editable"] = false;
  227. //set detail form client_id as readonly and for add dialog only
  228. //$col_2["editoptions"] = array("readonly"=>"readonly", "style"=>"border:0");
  229. $col_2["show"]["edit"] = false;
  230. $col_2s[] = $col_2;
  231.  
  232. $col_2 = array();
  233. $col_2["title"] = "fecha";
  234. $col_2["name"] = "fecha";
  235. $col_2["width"] = "15";
  236. $col_2["editable"] = true; // this column is editable
  237. # format as date
  238. $col_2["formatter"] = "date";
  239. # opts array can have these options: http://api.jqueryui.com/datepicker/
  240. $col_2["formatoptions"] = array("srcformat"=>'Y-m-d',"newformat"=>'d-m-Y', "opts" => array("changeYear" => true, "dateFormat"=>'yy-mm-dd', "minDate"=>"15-07-08"));
  241. $col_2s[] = $col_2;
  242.  
  243. $col_2 = array();
  244. $col_2["title"] = "incidencia";
  245. $col_2["name"] = "incidencia";
  246. $col_2["width"] = "100";
  247. $col_2["editable"] = true; // this column is editable
  248. $col_2["edittype"] = "textarea"; // render as textarea on edit
  249. $col_2["editoptions"] = array("rows"=>20, "cols"=>32); // with these attributes
  250. $col_2s[] = $col_2;
  251.  
  252.  
  253.  
  254.  
  255. $grid_2->set_columns($col_2s);
  256.  
  257. $grid_2->set_actions(array(
  258. "add"=>true, // allow/disallow add
  259. "edit"=>true, // allow/disallow edit
  260. "delete"=>true, // allow/disallow delete
  261. "rowactions"=>true, // show/hide row wise edit/del/save option
  262. "autofilter" => true, // show/hide autofilter for search
  263. "search" => "advance" // show single/multi field search condition (e.g. simple or advance)
  264. )
  265. );
  266.  
  267. $e["on_insert"] = array("add_incidencia", null, true);
  268. $e["on_update"] = array("update_incidencia", null, true);
  269. $grid_2->set_events($e);
  270.  
  271. function add_incidencia(&$data)
  272. {
  273. $id = intval($_GET["rowid"]);
  274. $data["params"]["id_don"] = $id;
  275. //$data["params"]["total"] = $data["params"]["amount"] + $data["params"]["tax"];
  276. }
  277.  
  278. function update_incidencia(&$data)
  279. {
  280. $id = intval($_GET["rowid"]);
  281. $data["params"]["id_don"] = $id;
  282.  
  283. }
  284.  
  285. // generate grid output, with unique grid nombre as 'list1'
  286. $out_detail = $grid_2->render("list2");
  287. ?>
  288. <!doctype html>
  289. <html>
  290. <head>
  291. <meta charset="utf-8">
  292.  
  293. <link rel="stylesheet" type="text/css" href="../phpgrid-full-v2.0/lib/js/themes/flick/jquery-ui.custom.css">
  294. <link rel="stylesheet" type="text/css" href="../phpgrid-full-v2.0/lib/js/jqgrid/css/ui.jqgrid.css">
  295.  
  296. <script src="../phpgrid-full-v2.0/lib/js/jquery.min.js"></script>
  297. <script src="../phpgrid-full-v2.0/lib/js/jqgrid/js/i18n/grid.locale-en.js"></script>
  298. <script src="../phpgrid-full-v2.0/lib/js/jqgrid/js/i18n/grid.locale-es.js"></script>
  299. <script src="../phpgrid-full-v2.0/lib/js/jqgrid/js/jquery.jqGrid.min.js"></script>
  300. <script src="../phpgrid-full-v2.0/lib/js/themes/jquery-ui.custom.min.js"></script></script>
  301.  
  302.  
  303. <!-- Add fancyBox main JS and CSS files -->
  304. <link type="text/css" rel="stylesheet" href="//cdn.jsdelivr.net/fancybox/2.1.4/jquery.fancybox.css" />
  305. <script type="text/javascript" src="//cdn.jsdelivr.net/fancybox/2.1.4/jquery.fancybox.js"></script>
  306.  
  307. </head>
  308. <body>
  309. <div style="margin:10px">
  310. Master Detail Grid, on same page
  311. <br>
  312. <br>
  313. <?php echo $out_master ?>
  314. <br>
  315. <?php echo $out_detail; ?>
  316. </div>
  317.  
  318.  
  319. </body>
  320. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement