Advertisement
Guest User

Multi Grid in Subgrid

a guest
Jul 6th, 2015
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.29 KB | None | 0 0
  1. file: master_grid.php
  2.  
  3.  <?php
  4. /**
  5.  * PHP Grid Component
  6.  *
  7.  * @author Abu Ghufran <gridphp@gmail.com> - http://www.phpgrid.org
  8.  * @version 1.5.2
  9.  * @license: see license.txt included in package
  10.  */
  11.  
  12. // include db config
  13. include_once("../../config.php");
  14.  
  15. // set up DB
  16. mysql_connect('localhost','root','root');
  17. mysql_select_db(PHPGRID_DBNAME);
  18.  
  19. // include and create object
  20. include(PHPGRID_LIBPATH."inc/jqgrid_dist.php");
  21.  
  22. // master grid
  23. $grid = new jqgrid();
  24. $opt["caption"] = "Clients Data";
  25. // following params will enable subgrid -- by default first column (PK) of parent is passed as param 'id'
  26. $opt["height"] = "600";
  27. $opt["width"] = "960";
  28. $opt["subGrid"] = true;
  29. $opt["subgridurl"] = "subgrid_detail.php";
  30.  
  31. $grid->set_options($opt);
  32. $grid->table = "clients";
  33.  
  34. $f2 = array();
  35. $f2["column"] = "name";
  36. $f2["op"] = "cn";
  37. $f2["value"] = "maria";
  38. $f2["css"] = "'background-color':'#f56b0a'";
  39. $f2_conditions[] = $f2;
  40. $grid->set_conditional_css($f2_conditions);
  41.  
  42. $grid->set_actions(array(    
  43.                         "add"=>true, // allow/disallow add
  44.                         "edit"=>true, // allow/disallow edit
  45.                         "delete"=>true, // allow/disallow delete
  46.                         "rowactions"=>false, // show/hide row wise edit/del/save option
  47.                         "export"=>true, // show/hide export to excel option
  48.                         "autofilter" => true, // show/hide autofilter for search
  49.                         "search" => "advance" // show single/multi field search condition (e.g. simple or advance)
  50.                     )
  51.                 );
  52.                
  53. $out_master = $grid->render("list1");
  54.  
  55.  
  56. ?>
  57. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  58. <html>
  59. <head>
  60.     <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/themes/redmond/jquery-ui.custom.css"></link>    
  61.     <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/jqgrid/css/ui.jqgrid.css"></link>    
  62.    
  63.     <script src="../../lib/js/jquery.min.js" type="text/javascript"></script>
  64.     <script src="../../lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
  65.     <script src="../../lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>    
  66.     <script src="../../lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
  67. </head>
  68. <body>
  69.     <div style="margin:10px">
  70.     Master Detail Grid, on same page
  71.     <br>
  72.     <br>
  73.     <?php echo $out_master ?>
  74.     <br>
  75.    
  76.     </div>
  77. </body>
  78. </html>
  79.  
  80.  
  81. file : subgrid_detail.php
  82.  
  83.  <?php
  84. /**
  85.  * PHP Grid Component
  86.  *
  87.  * @author Abu Ghufran <gridphp@gmail.com> - http://www.phpgrid.org
  88.  * @version 1.5.2
  89.  * @license: see license.txt included in package
  90.  */
  91.  
  92. // include db config
  93. include_once("../../config.php");
  94.  
  95. // set up DB
  96. mysql_connect('localhost','root','root');
  97. mysql_select_db(PHPGRID_DBNAME);
  98.  
  99. // include and create object
  100. include(PHPGRID_LIBPATH."inc/jqgrid_dist_old.php");
  101.  
  102.  
  103. // detail grid
  104. $grid = new jqgrid();
  105.  
  106. $opt = array();
  107. $opt["sortname"] = 'id'; // by default sort grid by this field
  108. $opt["sortorder"] = "desc"; // ASC or DESC
  109. $opt["height"] = "100";
  110. $opt["width"] = "400";
  111. $opt["caption"] = "Invoice Data"; // caption of grid
  112. $opt["multiselect"] = true; // allow you to multi-select through checkboxes
  113. $opt["export"] = array("filename"=>"my-file", "sheetname"=>"test"); // export to excel parameters
  114. $grid->set_options($opt);
  115.  
  116. $f2_conditions = array();
  117. $f2 = array();
  118. $f2["column"] = "amount";
  119. $f2["op"] = "cn";
  120. $f2["value"] = "200";
  121. $f2["css"] = "'background-color':'#8bf471'";
  122. $f2_conditions[] = $f2;
  123. $grid->set_conditional_css($f2_conditions);
  124.  
  125. $grid->set_actions(array(    
  126.                         "add"=>true, // allow/disallow add
  127.                         "edit"=>true, // allow/disallow edit
  128.                         "delete"=>true, // allow/disallow delete
  129.                         "rowactions"=>true, // show/hide row wise edit/del/save option
  130.                         "export"=>true, // show/hide export to excel option
  131.                         "autofilter" => true, // show/hide autofilter for search
  132.                         "search" => "advance" // show single/multi field search condition (e.g. simple or advance)
  133.                     )
  134.                 );
  135.  
  136. // receive id, selected row of parent grid
  137. $id = intval($_GET["rowid"]);
  138. // and use in sql for filteration
  139. $grid->select_command = "SELECT id,client_id,invdate,amount,tax,total FROM invheader WHERE client_id = $id";
  140. // this db table will be used for add,edit,delete
  141. $grid->table = "invheader";
  142.  
  143. $col = array();
  144. $col["title"] = "Id"; // caption of column
  145. $col["name"] = "id"; // field name, must be exactly same as with SQL prefix or db field
  146. $col["width"] = "10";
  147. $cols[] = $col;    
  148.  
  149. $col = array();
  150. $col["title"] = "Client Id";
  151. $col["name"] = "client_id";
  152. $col["width"] = "10";
  153. $col["editable"] = true;
  154. $col["hidden"] = true;
  155. $cols[] = $col;        
  156.  
  157. $col = array();
  158. $col["title"] = "Date";
  159. $col["name"] = "invdate";
  160. $col["width"] = "50";
  161. $col["editable"] = true; // this column is editable
  162. $col["editoptions"] = array("size"=>20); // with default display of textbox with size 20
  163. $col["editrules"] = array("required"=>true); // and is required
  164. $cols[] = $col;
  165.  
  166. $col = array();
  167. $col["title"] = "Amount";
  168. $col["name"] = "amount";
  169. $col["width"] = "50";
  170. $col["editable"] = true; // this column is editable
  171. $col["editoptions"] = array("size"=>20); // with default display of textbox with size 20
  172. $col["editrules"] = array("required"=>true); // and is required
  173. $cols[] = $col;
  174.  
  175. $grid->set_columns($cols);
  176. $e["on_insert"] = array("add_client", null, true);
  177. $grid->set_events($e);
  178.  
  179. function add_client(&$data)
  180. {
  181.     $id = intval($_GET["rowid"]);
  182.     $data["params"]["client_id"] = $id;
  183. }
  184.  
  185. // generate grid output, with unique grid name as 'list1'
  186. $out_list2 = $grid->render("list2");
  187.  
  188. // another detail grid.
  189.  
  190. $grid = new jqgrid();
  191.  
  192. $opt = array();
  193. $opt["sortname"] = 'id'; // by default sort grid by this field
  194. $opt["sortorder"] = "desc"; // ASC or DESC
  195. $opt["height"] = "100";
  196. $opt["width"] = "400";
  197. $opt["caption"] = "Invoice Detail Grid 2"; // caption of grid
  198. $grid->set_options($opt);
  199.  
  200. $grid->set_actions(array(    
  201.                         "add"=>false, // allow/disallow add
  202.                         "edit"=>false, // allow/disallow edit
  203.                         "delete"=>true, // allow/disallow delete
  204.                         "rowactions"=>false, // show/hide row wise edit/del/save option
  205.                         "export"=>true, // show/hide export to excel option
  206.                         "autofilter" => true, // show/hide autofilter for search
  207.                         "search" => "advance" // show single/multi field search condition (e.g. simple or advance)
  208.                     )
  209.                 );
  210.  
  211. // receive id, selected row of parent grid
  212. $id = intval($_GET["rowid"]);
  213. // and use in sql for filteration
  214. $grid->select_command = "SELECT id,client_id,invdate,amount,tax,total FROM invheader WHERE client_id = $id";
  215. // this db table will be used for add,edit,delete
  216. $grid->table = "invheader";
  217.  
  218. $col = array();
  219. $col["title"] = "Id"; // caption of column
  220. $col["name"] = "id"; // field name, must be exactly same as with SQL prefix or db field
  221. $col["width"] = "10";
  222. $cols[] = $col;    
  223.  
  224. $col = array();
  225. $col["title"] = "Client Id";
  226. $col["name"] = "client_id";
  227. $col["width"] = "10";
  228. $col["editable"] = true;
  229. $col["hidden"] = true;
  230. $cols[] = $col;        
  231.  
  232. $col = array();
  233. $col["title"] = "Date";
  234. $col["name"] = "invdate";
  235. $col["width"] = "50";
  236. $col["editable"] = true; // this column is editable
  237. $col["editoptions"] = array("size"=>20); // with default display of textbox with size 20
  238. $col["editrules"] = array("required"=>true); // and is required
  239. $cols[] = $col;
  240.  
  241. $f2_conditions = array();
  242. $f2 = array();
  243. $f2["column"] = "tax";
  244. $f2["op"] = "cn";
  245. $f2["value"] = "40";
  246. $f2["css"] = "'background-color':'#FF704D'";
  247. $f2_conditions[] = $f2;
  248. $grid->set_conditional_css($f2_conditions);
  249.  
  250. // generate grid output, with unique grid name as 'list1'
  251. $out_list3 = $grid->render("list3");
  252.  
  253. ?>
  254.    
  255.     <div style="float:left">
  256.     <?php echo $out_list2?>
  257.     </div>    
  258.     <div style="float:left; margin-left:20px">
  259.     <?php echo $out_list3?>
  260.     </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement