Advertisement
fsnoya

master-detail-fancy

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