Advertisement
Guest User

Multi Details

a guest
Apr 9th, 2015
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.42 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. // following params will enable subgrid -- by default first column (PK) of parent is passed as param 'id'
  24. $opt["detail_grid_id"] = "list2,list3";
  25. $opt["height"] = "200";
  26. $opt["width"] = "820";
  27. $grid->set_options($opt);
  28. $grid->table = "clients";
  29.  
  30. $f2 = array();
  31. $f2["column"] = "name";
  32. $f2["op"] = "cn";
  33. $f2["value"] = "ana";
  34. $f2["css"] = "'background-color':'#f56b0a'";
  35. $f2_conditions[] = $f2;
  36. $grid->set_conditional_css($f2_conditions);
  37.  
  38. $grid->set_actions(array(  
  39.                         "add"=>true, // allow/disallow add
  40.                         "edit"=>true, // allow/disallow edit
  41.                         "delete"=>true, // allow/disallow delete
  42.                         "rowactions"=>false, // show/hide row wise edit/del/save option
  43.                         "export"=>true, // show/hide export to excel option
  44.                         "autofilter" => true, // show/hide autofilter for search
  45.                         "search" => "advance" // show single/multi field search condition (e.g. simple or advance)
  46.                     )
  47.                 );
  48.                
  49. $out_master = $grid->render("list1");
  50.  
  51. // detail grid ******************************************************************************************
  52. $grid = new jqgrid();
  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"] = "100";
  58. $opt["width"] = "400";
  59. $opt["caption"] = "Invoice Data"; // caption of grid
  60. $opt["multiselect"] = true; // allow you to multi-select through checkboxes
  61. $opt["export"] = array("filename"=>"my-file", "sheetname"=>"test"); // export to excel parameters
  62. $grid->set_options($opt);
  63.  
  64. $f2_conditions = array();
  65. $f2 = array();
  66. $f2["column"] = "amount";
  67. $f2["op"] = "cn";
  68. $f2["value"] = "200";
  69. $f2["css"] = "'background-color':'#8bf471'";
  70. $f2_conditions[] = $f2;
  71. $grid->set_conditional_css($f2_conditions);
  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. // receive id, selected row of parent grid
  85. $id = intval($_GET["rowid"]);
  86. // and use in sql for filteration
  87. $grid->select_command = "SELECT id,client_id,invdate,amount,tax,total FROM invheader WHERE client_id = $id";
  88. // this db table will be used for add,edit,delete
  89. $grid->table = "invheader";
  90.  
  91. $col = array();
  92. $col["title"] = "Id"; // caption of column
  93. $col["name"] = "id"; // field name, must be exactly same as with SQL prefix or db field
  94. $col["width"] = "10";
  95. $cols[] = $col;
  96.  
  97. $col = array();
  98. $col["title"] = "Client Id";
  99. $col["name"] = "client_id";
  100. $col["width"] = "10";
  101. $col["editable"] = true;
  102. $col["hidden"] = true;
  103. $cols[] = $col;    
  104.  
  105. $col = array();
  106. $col["title"] = "Date";
  107. $col["name"] = "invdate";
  108. $col["width"] = "50";
  109. $col["editable"] = true; // this column is editable
  110. $col["editoptions"] = array("size"=>20); // with default display of textbox with size 20
  111. $col["editrules"] = array("required"=>true); // and is required
  112. $cols[] = $col;
  113.  
  114. $col = array();
  115. $col["title"] = "Amount";
  116. $col["name"] = "amount";
  117. $col["width"] = "50";
  118. $col["editable"] = true; // this column is editable
  119. $col["editoptions"] = array("size"=>20); // with default display of textbox with size 20
  120. $col["editrules"] = array("required"=>true); // and is required
  121. $cols[] = $col;
  122.  
  123. $grid->set_columns($cols);
  124. $e["on_insert"] = array("add_client", null, true);
  125. $grid->set_events($e);
  126.  
  127. function add_client(&$data)
  128. {
  129.     $id = intval($_GET["rowid"]);
  130.     $data["params"]["client_id"] = $id;
  131. }
  132.  
  133. // generate grid output, with unique grid name as 'list1'
  134. $out_list2 = $grid->render("list2");
  135.  
  136. // another detail grid. ***********************************************************************
  137.  
  138. $grid = new jqgrid();
  139.  
  140. $opt = array();
  141. $opt["sortname"] = 'id'; // by default sort grid by this field
  142. $opt["sortorder"] = "desc"; // ASC or DESC
  143. $opt["height"] = "100";
  144. $opt["width"] = "400";
  145. $opt["caption"] = "Invoice Detail Grid 2"; // caption of grid
  146. $grid->set_options($opt);
  147.  
  148. $grid->set_actions(array(  
  149.                         "add"=>true, // allow/disallow add
  150.                         "edit"=>true, // allow/disallow edit
  151.                         "delete"=>true, // allow/disallow delete
  152.                         "rowactions"=>false, // show/hide row wise edit/del/save option
  153.                         "export"=>true, // show/hide export to excel option
  154.                         "autofilter" => true, // show/hide autofilter for search
  155.                         "search" => "advance" // show single/multi field search condition (e.g. simple or advance)
  156.                     )
  157.                 );
  158.  
  159. // receive id, selected row of parent grid
  160. $id = intval($_GET["rowid"]);
  161. // and use in sql for filteration
  162. $grid->select_command = "SELECT id,client_id,invdate,amount,tax,total FROM invheader WHERE client_id = $id";
  163. // this db table will be used for add,edit,delete
  164. $grid->table = "invheader";
  165.  
  166. $col = array();
  167. $col["title"] = "Id"; // caption of column
  168. $col["name"] = "id"; // field name, must be exactly same as with SQL prefix or db field
  169. $col["width"] = "10";
  170. $col["hidden"] = true; // hide on grid
  171. $cols[] = $col;
  172.  
  173. $col = array();
  174. $col["title"] = "Client Id";
  175. $col["name"] = "client_id";
  176. $col["width"] = "10";
  177. $col["editable"] = true;
  178. $col["hidden"] = true;
  179. $cols[] = $col;    
  180.  
  181. $col = array();
  182. $col["title"] = "Date";
  183. $col["name"] = "invdate";
  184. $col["width"] = "50";
  185. $col["editable"] = true; // this column is editable
  186. $col["editoptions"] = array("size"=>20); // with default display of textbox with size 20
  187. $col["editrules"] = array("required"=>true); // and is required
  188. $cols[] = $col;
  189.  
  190. $f2_conditions = array();
  191. $f2 = array();
  192. $f2["column"] = "tax";
  193. $f2["op"] = "cn";
  194. $f2["value"] = "40";
  195. $f2["css"] = "'background-color':'#FF704D'";
  196. $f2_conditions[] = $f2;
  197. $grid->set_conditional_css($f2_conditions);
  198.  
  199. // generate grid output, with unique grid name as 'list1'
  200. $out_list3 = $grid->render("list3");
  201.  
  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/flick/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.     <script src="../../lib/js/jquery.min.js" type="text/javascript"></script>
  210.     <script src="../../lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
  211.     <script src="../../lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script> 
  212.     <script src="../../lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
  213. </head>
  214. <body>
  215.     <div style="margin:10px">
  216.     Master Detail Grid, on same page
  217.     <br>
  218.     <br>
  219.     <?php echo $out_master ?>
  220.     <br>
  221.    
  222.     <div style="float:left">
  223.     <?php echo $out_list2?>
  224.     </div> 
  225.     <div style="float:left; margin-left:20px">
  226.     <?php echo $out_list3?>
  227.     </div>
  228.    
  229.    
  230.     </div>
  231. </body>
  232. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement