Advertisement
Guest User

Untitled

a guest
Jul 14th, 2014
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.60 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"] = "Products Categories";
  23. $opt["multiselect"] = true;
  24. // following params will enable subgrid -- by default first column (PK) of parent is passed as param 'id'
  25. $opt["detail_grid_id"] = "list2";
  26. $grid->set_options($opt);
  27.  
  28. $grid->select_command ="select * from category ";
  29. $grid->table = "category";
  30.    
  31. $col = array();
  32. $col["title"] = "Category ID";
  33. $col["name"] = "catid";
  34. $col["width"] = "30";
  35. $col["editable"] = false;
  36. //$col["hidden"] = true;
  37. $cols[] = $col;    
  38. $col = array();
  39. $col["title"] = "Company ID";
  40. $col["name"] = "comp_id";
  41. $col["width"] = "20";
  42. $col["editable"] = false;
  43. $col["hidden"] = true;
  44. $cols[] = $col;
  45. $col = array();
  46. $col["title"] = "Category Name";
  47. $col["name"] = "cat_name";
  48. $col["width"] = "150";
  49. $col["editable"] = true; // this column is editable
  50. $col["editoptions"] = array("size"=>20); // with default display of textbox with size 20
  51. $col["editrules"] = array("required"=>true); // and is required
  52. $cols[] = $col;
  53.  
  54. $col = array();
  55. $col["title"] = "Active";
  56. $col["name"] = "active";
  57. $col["width"] = "20";
  58. $col["editable"] = true;
  59. $col["edittype"] = "checkbox"; // render as checkbox
  60. $col["editoptions"] = array("value"=>"1:0"); // with these values "checked_value:unchecked_value"
  61. $col["formatter"] = "checkbox";
  62. $cols[] = $col;
  63.  
  64. $grid->set_columns($cols);
  65. $grid->set_actions(array(  
  66.                         "add"=>true, // allow/disallow add
  67.                         "edit"=>true, // allow/disallow edit
  68.                         "delete"=>true, // allow/disallow delete
  69.                         "rowactions"=>true, // show/hide row wise edit/del/save option
  70.                         "export"=>true, // show/hide export to excel option
  71.                         "autofilter" => true, // show/hide autofilter for search
  72.                         "search" => "advance" // show single/multi field search condition (e.g. simple or advance)
  73.                     )
  74.                 );
  75.                
  76. $out_master = $grid->render("list1");
  77.  
  78. // detail grid
  79. $grid = new jqgrid();
  80.  
  81. $opt = array();
  82. $opt["sortname"] = 'subcat_id'; // by default sort grid by this field
  83. $opt["sortorder"] = "desc"; // ASC or DESC
  84. $opt["height"] = ""; // autofit height of subgrid
  85. $opt["caption"] = "Sub Category list"; // caption of grid
  86. $opt["export"] = array("filename"=>"my-file", "sheetname"=>"test"); // export to excel parameters
  87. $opt["detail_grid_id"] = "list3";
  88. $grid->set_options($opt);
  89.  
  90. $grid->set_actions(array(  
  91.                         "add"=>true, // allow/disallow add
  92.                         "edit"=>true, // allow/disallow edit
  93.                         "delete"=>true, // allow/disallow delete
  94.                         "rowactions"=>true, // show/hide row wise edit/del/save option
  95.                         "export"=>true, // show/hide export to excel option
  96.                         "autofilter" => true, // show/hide autofilter for search
  97.                         "search" => "advance" // show single/multi field search condition (e.g. simple or advance)
  98.                     )
  99.                 );
  100.  
  101. // receive id, selected row of parent grid
  102. $id = intval($_GET["rowid"]);
  103. // and use in sql for filteration
  104. $grid->select_command = "SELECT subcat_id, subcat_name, active FROM subcategory where cat_id = $id";
  105. // this db table will be used for add,edit,delete
  106. $grid->table = "subcategory";
  107.  
  108. $col = array();
  109. $col["title"] = "Id"; // caption of column
  110. $col["name"] = "subcat_id"; // field name, must be exactly same as with SQL prefix or db field
  111. $col["width"] = "10";
  112. $cols[] = $col;
  113.  
  114. $col = array();
  115. $col["title"] = "subcategory Name";
  116. $col["name"] = "subcat_name";
  117. $col["width"] = "10";
  118. $col["editable"] = true;
  119. //$col["hidden"] = true;
  120. $cols[] = $col;    
  121.  
  122. $col = array();
  123. $col["title"] = "Active";
  124. $col["name"] = "active";
  125. $col["width"] = "20";
  126. $col["editable"] = true;
  127. $col["edittype"] = "checkbox"; // render as checkbox
  128. $col["editoptions"] = array("value"=>"1:0"); // with these values "checked_value:unchecked_value"
  129. $col["formatter"] = "checkbox";
  130. $cols[] = $col;
  131. //$col = array();
  132. //$col["title"] = "Amount";
  133. //$col["name"] = "amount";
  134. //$col["width"] = "50";
  135. //$col["editable"] = true; // this column is editable
  136. //$col["editoptions"] = array("size"=>20); // with default display of textbox with size 20
  137. //$col["editrules"] = array("required"=>true); // and is required
  138. //$cols[] = $col;
  139.  
  140. $grid->set_columns($cols);
  141. $e["on_insert"] = array("add_client", null, true);
  142. $grid->set_events($e);
  143.  
  144. function add_client(&$data)
  145. {
  146.     $id = intval($_GET["rowid"]);
  147.     $data["params"]["subcat_id"] = $id;
  148. }
  149.  
  150. // generate grid output, with unique grid name as 'list1'
  151. $out_detail = $grid->render("list2");
  152.  
  153.  
  154. // detail detail grid
  155. $grid = new jqgrid();
  156. $opt = array();
  157. $opt["sortname"] = 'product_id'; // by default sort grid by this field
  158. $opt["sortorder"] = "desc"; // ASC or DESC
  159. $opt["height"] = ""; // autofit height of subgrid
  160. $opt["caption"] = "Invoice Data Detail"; // caption of grid
  161. $grid->set_options($opt);
  162.  
  163. $grid->set_actions(array(  
  164.                         "add"=>false, // allow/disallow add
  165.                         "edit"=>false, // allow/disallow edit
  166.                         "delete"=>false, // allow/disallow delete
  167.                         "rowactions"=>false, // show/hide row wise edit/del/save option
  168.                         "autofilter" => true, // show/hide autofilter for search
  169.                         "search" => "advance" // show single/multi field search condition (e.g. simple or advance)
  170.                     )
  171.                 );
  172. // receive id, selected row of parent grid
  173. $id = intval($_GET["rowid"]);
  174. $grid->select_command = "SELECT * FROM product WHERE subcat_id = $id";
  175. $grid->table = "product";
  176. $out_detail_detail = $grid->render("list3");
  177.  
  178. ?>
  179. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  180. <html>
  181. <head>
  182.     <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/themes/redmond/jquery-ui.custom.css"></link>  
  183.     <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/jqgrid/css/ui.jqgrid.css"></link> 
  184.    
  185.     <script src="../../lib/js/jquery.min.js" type="text/javascript"></script>
  186.     <script src="../../lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
  187.     <script src="../../lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script> 
  188.     <script src="../../lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
  189. </head>
  190. <body>
  191.     <div style="margin:10px">
  192.     <?php echo $out_master ?>
  193.     <br>
  194.     <br>
  195.     <?php echo $out_detail?>
  196.     <br>
  197.     <br>
  198.     <?php echo $out_detail_detail?>
  199.     </div>
  200. </body>
  201. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement