Advertisement
Guest User

Untitled

a guest
Mar 31st, 2015
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.38 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 1.5.2
  7.  * @license: see license.txt included in package
  8.  */
  9.  
  10. // include db config
  11. include_once("../../config.php");
  12.  
  13. // set up DB
  14. mysql_connect(PHPGRID_DBHOST, PHPGRID_DBUSER, PHPGRID_DBPASS);
  15. mysql_select_db(PHPGRID_DBNAME);
  16.  
  17. // include and create object
  18. include(PHPGRID_LIBPATH."inc/jqgrid_dist.php");
  19.  
  20. // master grid
  21. $grid = new jqgrid();
  22. $opt["caption"] = "Clients Data";
  23. $opt["height"] = "250";
  24. $opt["sortorder"] = "desc";
  25. // following params will enable subgrid -- by default first column (PK) of parent is passed as param 'id'
  26. $opt["detail_grid_id"] = "list2";
  27.  
  28.  
  29. // extra params passed to detail grid, column name comma separated
  30. $opt["subgridparams"] = "client_id,gender,company";
  31. $opt["multiselect"] = false;
  32. $opt["export"] = array("filename"=>"my-file", "sheetname"=>"test", "format"=>"pdf");
  33. $opt["export"]["range"] = "filtered";
  34. $grid->set_options($opt);
  35. $grid->table = "clients";
  36.  
  37. $grid->set_actions(array(  
  38.                         "add"=>true, // allow/disallow add
  39.                         "edit"=>true, // allow/disallow edit
  40.                         "delete"=>true, // allow/disallow delete
  41.                         "rowactions"=>true, // show/hide row wise edit/del/save option
  42.                         "export"=>true, // show/hide export to excel option
  43.                         "autofilter" => true, // show/hide autofilter for search
  44.                         "search" => "advance" // show single/multi field search condition (e.g. simple or advance)
  45.                     )
  46.                 );
  47.                
  48. $out_master = $grid->render("list1");
  49.  
  50. // detail grid
  51. $grid = new jqgrid();
  52.  
  53.  
  54. $opt = array();
  55. $opt["sortname"] = 'id'; // by default sort grid by this field
  56. $opt["sortorder"] = "desc"; // ASC or DESC
  57. $opt["height"] = ""; // autofit height of subgrid
  58. $opt["caption"] = "Invoice Data"; // caption of grid
  59. $opt["multiselect"] = true; // allow you to multi-select through checkboxes
  60. $opt["reloadedit"] = true; // allow you to multi-select through checkboxes
  61. $opt["export"] = array("filename"=>"my-file", "sheetname"=>"test", "format"=>"pdf"); // export to excel parameters
  62. $opt["export"]["range"] = "filtered";
  63.  
  64. // Check if master record is selected before detail addition
  65. // $opt["add_options"]["beforeInitData"] = "function(formid){ var selr = jQuery('#list1').jqGrid('getGridParam','selrow'); if (!selr) { alert('Please select master record first'); return false; } }";
  66.  
  67. // reload master after detail update
  68. $opt["onAfterSave"] = "function(){ jQuery('#list1').trigger('reloadGrid',[{jqgrid_page:1}]); }";
  69.  
  70.  
  71. $grid->set_options($opt);
  72.  
  73. $grid->set_actions(array(  
  74.                         "add"=>true, // allow/disallow add
  75.                         "edit"=>true, // allow/disallow edit
  76.                         "delete"=>true, // allow/disallow delete
  77.                         "rowactions"=>true, // show/hide row wise edit/del/save option
  78.                         "export"=>true, // show/hide export to excel option
  79.                         "autofilter" => true, // show/hide autofilter for search
  80.                         "search" => "advance" // show single/multi field search condition (e.g. simple or advance)
  81.                     )
  82.                 );
  83.  
  84.  
  85. // receive id, selected row of parent grid
  86. $id = intval($_GET["rowid"]);
  87. $gender = $_GET["gender"];
  88. $company = $_GET["company"];
  89. $cid = intval($_GET["client_id"]);
  90.  
  91. // for non-int fields as PK
  92. // $id = (empty($_GET["rowid"])?0:$_GET["rowid"]);
  93.  
  94. // and use in sql for filteration
  95. $grid->select_command = "SELECT id,client_id,invdate,amount,tax,note,total,'$company' as 'company' FROM invheader WHERE client_id = $id";
  96. // this db table will be used for add,edit,delete
  97. $grid->table = "invheader";
  98.  
  99. $col = array();
  100. $col["title"] = "Id"; // caption of column
  101. $col["name"] = "id"; // field name, must be exactly same as with SQL prefix or db field
  102. $col["width"] = "10";
  103. $cols[] = $col;
  104.  
  105. $col = array();
  106. $col["title"] = "Company"; // caption of column
  107. $col["name"] = "company"; // field name, must be exactly same as with SQL prefix or db field
  108. $col["width"] = "100";
  109. $col["editable"] = false;
  110. $col["show"] = array("list"=>true,"edit"=>true,"add"=>false,"view"=>false);
  111. $cols[] = $col;
  112.        
  113. $col = array();
  114. $col["title"] = "Client";
  115. $col["name"] = "client_id";
  116. $col["width"] = "100";
  117. $col["align"] = "left";
  118. $col["search"] = true;
  119. $col["editable"] = false;
  120. $cols[] = $col;
  121.  
  122. $col = array();
  123. $col["title"] = "Date";
  124. $col["name"] = "invdate";
  125. $col["formatter"] = "date";
  126. $col["width"] = "100";
  127. $col["search"] = true;
  128. $col["editable"] = true;
  129. $cols[] = $col;
  130.  
  131. $col = array();
  132. $col["title"] = "Amount";
  133. $col["name"] = "amount";
  134. $col["width"] = "100";
  135. $col["search"] = true;
  136. $col["editable"] = true;
  137. $cols[] = $col;
  138.  
  139. $col = array();
  140. $col["title"] = "Tax";
  141. $col["name"] = "tax";
  142. $col["width"] = "100";
  143. $col["search"] = true;
  144. $col["editable"] = true;
  145. $cols[] = $col;
  146.  
  147. $col = array();
  148. $col["title"] = "Total";
  149. $col["name"] = "total";
  150. $col["width"] = "100";
  151. $col["search"] = true;
  152. $col["editable"] = false;
  153. $cols[] = $col;
  154.  
  155. $col = array();
  156. $col["title"] = "Invoices";
  157. $col["name"] = "note";
  158. $col["width"] = "100";
  159. $col["search"] = true;
  160. $col["editable"] = true;
  161. $cols[] = $col;
  162.  
  163. $grid->set_columns($cols);
  164. $e["on_insert"] = array("add_client", null, true);
  165. $e["on_update"] = array("update_client", null, true);
  166. $grid->set_events($e);
  167.  
  168.  
  169. $grid->set_actions(array(  
  170.                         "add"=>true, // allow/disallow add
  171.                         "edit"=>true, // allow/disallow edit
  172.                         "delete"=>true, // allow/disallow delete
  173.                         "inlineadd"=>true, // allow/disallow delete
  174.                         "rowactions"=>true, // show/hide row wise edit/del/save option
  175.                         "autofilter" => true, // show/hide autofilter for search
  176.                         "search" => "advance" // show single/multi field search condition (e.g. simple or advance)
  177.                     )
  178.                 );
  179.  
  180. $grid["altRows"] = true;
  181. $grid["altclass"] = "myAltRowClass";
  182. $g->set_options($grid);
  183.  
  184.            
  185. function add_client(&$data)
  186. {
  187.     $id = intval($_GET["rowid"]);
  188.     $data["params"]["client_id"] = $id;
  189.     $data["params"]["total"] = $data["params"]["amount"] + $data["params"]["tax"];
  190. }
  191.  
  192. function update_client(&$data)
  193. {
  194.     $id = intval($_GET["rowid"]);
  195.     $data["params"]["client_id"] = $id;
  196.     $data["params"]["total"] = $data["params"]["amount"] + $data["params"]["tax"];
  197. }
  198.  
  199.  
  200. // generate grid output, with unique grid name as 'list1'
  201. $out_detail = $grid->render("list2");
  202. ?>
  203. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  204. <html>
  205. <head>
  206.     <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/themes/start/jquery-ui.custom.css"></link>
  207.     <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/jqgrid/css/ui.jqgrid.css"></link> 
  208.    
  209.    
  210.     <script src="../../lib/js/jquery.min.js" type="text/javascript"></script>
  211.     <script src="../../lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
  212.     <script src="../../lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script> 
  213.     <script src="../../lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
  214.     <script src="//cdn.jsdelivr.net/jquery.hotkeys/0.8b/jquery.hotkeys.js"></script>
  215. </head>
  216. <body>
  217.     <div style="margin:10px">
  218.         <style>
  219.     .myAltRowClass { background-color: #DDDDDC; background-image: none; }
  220.     </style>
  221.  
  222.     <br>
  223.     <br>
  224.     <?php echo $out_master ?>
  225.     <br>
  226.     <br>
  227.     <?php echo $out_detail; ?>
  228.     </div>
  229.    
  230.     <script>
  231.     // insert key to add new row, tab to focus on save icon & press enter to save
  232.     $(document).bind('keyup', 'insert', function(){
  233.           jQuery('#list2_iladd').click();
  234.         });
  235.        
  236.     </script>  
  237. </body>
  238. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement