Advertisement
Guest User

Untitled

a guest
Jun 5th, 2017
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.78 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 2.0.0
  7.  * @license: see license.txt included in package
  8.  */
  9.  
  10. // include db config
  11. include_once("config.php");
  12.  
  13. // include and create object
  14. include(PHPGRID_LIBPATH."inc/jqgrid_dist.php");
  15.  
  16. // Database config file to be passed in phpgrid constructor
  17. $db_conf = array(      
  18.                     "type"         => PHPGRID_DBTYPE,  
  19.                     "server"     => PHPGRID_DBHOST,
  20.                     "user"         => PHPGRID_DBUSER,
  21.                     "password"     => PHPGRID_DBPASS,
  22.                     "database"     => PHPGRID_DBNAME
  23.                 );
  24.  
  25. // master grid
  26. $grid = new jqgrid($db_conf);
  27. $opt["caption"] = "Clients Data";
  28. // following params will enable subgrid -- by default first column (PK) of parent is passed as param 'id'
  29. $opt["detail_grid_id"] = "list2,list3";
  30. $opt["height"] = "200";
  31. $opt["width"] = "820";
  32. $opt["multiselect"] = true;
  33.  
  34. // select row after addition
  35. $opt["add_options"]["afterComplete"] = "function (response, postdata) { r = JSON.parse(response.responseText); $('#list1').setSelection(r.id); }";
  36.  
  37. $grid->set_options($opt);
  38. $grid->table = "clients";
  39.  
  40. // for cell that have particular name
  41. $f2 = array();
  42. $f2["column"] = "name";
  43. $f2["op"] = "cn";
  44. $f2["value"] = "maria";
  45. $f2["css"] = "'background-color':'#f56b0a'";
  46. $f2_conditions[] = $f2;
  47. $grid->set_conditional_css($f2_conditions);
  48.  
  49. $grid->set_actions(array(    
  50.                         "add"=>true, // allow/disallow add
  51.                         "edit"=>true, // allow/disallow edit
  52.                         "delete"=>true, // allow/disallow delete
  53.                         "rowactions"=>false, // show/hide row wise edit/del/save option
  54.                         "autofilter" => true, // show/hide autofilter for search
  55.                         "search" => "advance" // show single/multi field search condition (e.g. simple or advance)
  56.                     )  
  57.                 );
  58.                  
  59. $out_master = $grid->render("list1");
  60.  
  61. // detail grid
  62. $grid = new jqgrid($db_conf);
  63.  
  64. $opt = array();
  65. $opt["sortname"] = 'id'; // by default sort grid by this field
  66. $opt["sortorder"] = "desc"; // ASC or DESC
  67. $opt["height"] = "100";
  68. $opt["width"] = "400";
  69. $opt["caption"] = "Invoice Data"; // caption of grid
  70. $opt["multiselect"] = true; // allow you to multi-select through checkboxes
  71. $opt["export"] = array("filename"=>"my-file", "sheetname"=>"test"); // export to excel parameters
  72.  
  73. // only use ' for function code
  74. $opt["onAfterSave"] = "function() { var rowid = $('#list1').jqGrid('getGridParam','selrow'); $('#list1').trigger('reloadGrid', [{current:true}]); $('#list1').setSelection(rowid,true); }";
  75.  
  76. $grid->set_options($opt);
  77.  
  78. $f2_conditions = array();
  79. $f2 = array();
  80. $f2["column"] = "amount";
  81. $f2["op"] = "cn";
  82. $f2["value"] = "200";
  83. $f2["css"] = "'background-color':'#8bf471'";
  84. $f2_conditions[] = $f2;
  85. $grid->set_conditional_css($f2_conditions);
  86.  
  87. $grid->set_actions(array(    
  88.                         "add"=>true, // allow/disallow add
  89.                         "edit"=>true, // allow/disallow edit
  90.                         "delete"=>true, // allow/disallow delete
  91.                         "rowactions"=>true, // show/hide row wise edit/del/save option
  92.                         "autofilter" => true, // show/hide autofilter for search
  93.                         "search" => "advance" // show single/multi field search condition (e.g. simple or advance)
  94.                     )  
  95.                 );
  96.  
  97. // receive id, selected row of parent grid
  98. $id = intval($_GET["rowid"]);
  99. // and use in sql for filteration
  100. $grid->select_command = "SELECT id,client_id,invdate,amount,tax,total FROM invheader WHERE client_id IN ( $id )";
  101. // this db table will be used for add,edit,delete
  102. $grid->table = "invheader";
  103.  
  104. $col = array();
  105. $col["title"] = "Id"; // caption of column
  106. $col["name"] = "id"; // field name, must be exactly same as with SQL prefix or db field
  107. $col["width"] = "10";
  108. $cols[] = $col;    
  109.  
  110. $col = array();
  111. $col["title"] = "Client Id";
  112. $col["name"] = "client_id";
  113. $col["width"] = "10";
  114. $col["editable"] = true;
  115. $col["hidden"] = true;
  116. $cols[] = $col;        
  117.  
  118. $col = array();
  119. $col["title"] = "Date";
  120. $col["name"] = "invdate";
  121. $col["width"] = "50";
  122. $col["editable"] = true; // this column is editable
  123. $col["editoptions"] = array("size"=>20); // with default display of textbox with size 20
  124. $col["editrules"] = array("required"=>true); // and is required
  125. $cols[] = $col;
  126.  
  127. $col = array();
  128. $col["title"] = "Amount";
  129. $col["name"] = "amount";
  130. $col["width"] = "50";
  131. $col["editable"] = true; // this column is editable
  132. $col["editoptions"] = array("size"=>20); // with default display of textbox with size 20
  133. $col["editrules"] = array("required"=>true); // and is required
  134. $cols[] = $col;
  135.  
  136. $grid->set_columns($cols);
  137. $e["on_insert"] = array("add_client", null, true);
  138. $grid->set_events($e);
  139.  
  140. function add_client(&$data)
  141. {
  142.     $id = intval($_GET["rowid"]);
  143.     $data["params"]["client_id"] = $id;
  144. }
  145.  
  146. // generate grid output, with unique grid name as 'list1'
  147. $out_list2 = $grid->render("list2");
  148.  
  149. // another detail grid.
  150. $grid = new jqgrid($db_conf);
  151.  
  152. $opt = array();
  153. $opt["sortname"] = 'id'; // by default sort grid by this field
  154. $opt["sortorder"] = "desc"; // ASC or DESC
  155. $opt["height"] = "100";
  156. $opt["width"] = "400";
  157. $opt["caption"] = "Invoice Detail Grid 2"; // caption of grid
  158. $grid->set_options($opt);
  159.  
  160. $grid->set_actions(array(    
  161.                         "add"=>false, // allow/disallow add
  162.                         "edit"=>false, // allow/disallow edit
  163.                         "delete"=>true, // allow/disallow delete
  164.                         "rowactions"=>false, // show/hide row wise edit/del/save option
  165.                         "autofilter" => true, // show/hide autofilter for search
  166.                         "search" => "advance" // show single/multi field search condition (e.g. simple or advance)
  167.                     )  
  168.                 );
  169.  
  170. // receive id, selected row of parent grid
  171. $id = intval($_GET["rowid"]);
  172. // and use in sql for filteration
  173. $grid->select_command = "SELECT id,client_id,invdate,amount,tax,total FROM invheader WHERE client_id = $id";
  174. // this db table will be used for add,edit,delete
  175. $grid->table = "invheader";
  176.  
  177. $f2_conditions = array();
  178. $f2 = array();
  179. $f2["column"] = "tax";
  180. $f2["op"] = "cn";
  181. $f2["value"] = "40";
  182. $f2["css"] = "'background-color':'#FF704D'";
  183. $f2_conditions[] = $f2;
  184. $grid->set_conditional_css($f2_conditions);
  185.  
  186. // generate grid output, with unique grid name as 'list1'
  187. $out_list3 = $grid->render("list3");
  188.  
  189. ?>
  190. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  191. <html>
  192. <head>
  193.     <link rel="stylesheet" type="text/css" media="screen" href="lib/js/themes/redmond/jquery-ui.custom.css"></link>    
  194.     <link rel="stylesheet" type="text/css" media="screen" href="lib/js/jqgrid/css/ui.jqgrid.css"></link>    
  195.      
  196.     <script src="lib/js/jquery.min.js" type="text/javascript"></script>
  197.     <script src="lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
  198.     <script src="lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>    
  199.     <script src="lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
  200. </head>
  201. <body>
  202.     <div style="margin:10px">
  203.     Multiple Detail Grids
  204.     <br>
  205.     <br>
  206.     <?php echo $out_master ?>
  207.     <br>
  208.      
  209.     <div style="float:left">
  210.     <?php echo $out_list2?>
  211.     </div>    
  212.      
  213.     <div style="float:left; margin-left:20px">
  214.     <?php echo $out_list3?>
  215.     </div>
  216.      
  217.     </div>
  218. </body>
  219. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement