Advertisement
bionicspider

phpgrid multigrid issue 1

Nov 3rd, 2014
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.40 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("../phpgridliwsa/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("../phpgridliwsa/lib/inc/jqgrid_dist.php");
  19.  
  20. // master grid
  21. $grid = new jqgrid();
  22. $opt["caption"] = "Clients Data";
  23. $opt["height"] = "150";
  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. // extra params passed to detail grid, column name comma separated
  29. //$opt["subgridparams"] = "client_id,gender,company";
  30. $opt["multiselect"] = false;
  31. $opt["export"] = array("filename"=>"my-file", "sheetname"=>"test", "format"=>"pdf");
  32. $opt["export"]["range"] = "filtered";
  33. $grid->set_options($opt);
  34. $grid->table = "cus_ypp_requests";
  35.  
  36. $grid->set_actions(array(  
  37.                         "add"=>true, // allow/disallow add
  38.                         "edit"=>true, // allow/disallow edit
  39.                         "delete"=>true, // allow/disallow delete
  40.                         "rowactions"=>true, // show/hide row wise edit/del/save option
  41.                         "export"=>true, // show/hide export to excel option
  42.                         "autofilter" => true, // show/hide autofilter for search
  43.                         "search" => "advance" // show single/multi field search condition (e.g. simple or advance)
  44.                     )
  45.                 );
  46.                
  47. $out_master = $grid->render("list1");
  48.  
  49. // detail grid
  50. $grid = new jqgrid();
  51.  
  52. $opt = array();
  53. $opt["sortname"] = 'id'; // by default sort grid by this field
  54. $opt["sortorder"] = "desc"; // ASC or DESC
  55. $opt["height"] = ""; // autofit height of subgrid
  56. $opt["caption"] = "Invoice Data"; // caption of grid
  57. $opt["multiselect"] = true; // allow you to multi-select through checkboxes
  58. $opt["reloadedit"] = true; // allow you to multi-select through checkboxes
  59. $opt["export"] = array("filename"=>"my-file", "sheetname"=>"test", "format"=>"pdf"); // export to excel parameters
  60. $opt["export"]["range"] = "filtered";
  61.  
  62. // Check if master record is selected before detail addition
  63. // $opt["add_options"]["beforeInitData"] = "function(formid){ var selr = jQuery('#list1').jqGrid('getGridParam','selrow'); if (!selr) { alert('Please select master record first'); return false; } }";
  64.  
  65. // reload master after detail update
  66. $opt["onAfterSave"] = "function(){ jQuery('#list1').trigger('reloadGrid',[{jqgrid_page:1}]); }";
  67.  
  68. $grid->set_options($opt);
  69.  
  70. $grid->set_actions(array(  
  71.                         "add"=>true, // allow/disallow add
  72.                         "edit"=>true, // allow/disallow edit
  73.                         "delete"=>true, // allow/disallow delete
  74.                         "rowactions"=>true, // show/hide row wise edit/del/save option
  75.                         "export"=>true, // show/hide export to excel option
  76.                         "autofilter" => true, // show/hide autofilter for search
  77.                         "search" => "advance" // show single/multi field search condition (e.g. simple or advance)
  78.                     )
  79.                 );
  80.  
  81.  
  82. // receive id, selected row of parent grid
  83. $id = intval($_GET["rowid"]);
  84. //$gender = $_GET["gender"];
  85. //$company = $_GET["company"];
  86. //$cid = intval($_GET["client_id"]);
  87.  
  88. // for non-int fields as PK
  89. // $id = (empty($_GET["rowid"])?0:$_GET["rowid"]);
  90.  
  91. // and use in sql for filteration
  92. $grid->select_command = "SELECT id, hteam_id, hteam_div_id FROM cus_ypp_requests WHERE client_id = $id";
  93. // this db table will be used for add,edit,delete
  94. $grid->table = "cus_ypp_requests";
  95.  
  96. $col = array();
  97. $col["title"] = "Id"; // caption of column
  98. $col["name"] = "id"; // field name, must be exactly same as with SQL prefix or db field
  99. $col["width"] = "10";
  100. $cols[] = $col;
  101.  
  102. $col = array();
  103. $col["title"] = "Company"; // caption of column
  104. $col["name"] = "hteam_id"; // field name, must be exactly same as with SQL prefix or db field
  105. $col["width"] = "100";
  106. $col["editable"] = false;
  107. $col["show"] = array("list"=>true,"edit"=>true,"add"=>false,"view"=>false);
  108. $cols[] = $col;
  109.        
  110. $col = array();
  111. $col["title"] = "Client";
  112. $col["name"] = "hteam_div_id";
  113. $col["width"] = "100";
  114. $col["align"] = "left";
  115. $col["search"] = true;
  116. $col["editable"] = false;
  117. $cols[] = $col;
  118.  
  119. $grid->set_columns($cols);
  120. $e["on_insert"] = array("add_client", null, true);
  121. $e["on_update"] = array("update_client", null, true);
  122. $grid->set_events($e);
  123.  
  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.                         "inlineadd"=>true, // allow/disallow delete
  130.                         "rowactions"=>true, // show/hide row wise edit/del/save 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.            
  137. function add_client(&$data)
  138. {
  139.     $id = intval($_GET["rowid"]);
  140.     $data["params"]["client_id"] = $id;
  141.     $data["params"]["total"] = $data["params"]["amount"] + $data["params"]["tax"];
  142. }
  143.  
  144. function update_client(&$data)
  145. {
  146.     $id = intval($_GET["rowid"]);
  147.     $data["params"]["client_id"] = $id;
  148.     $data["params"]["total"] = $data["params"]["amount"] + $data["params"]["tax"];
  149. }
  150.  
  151. // generate grid output, with unique grid name as 'list1'
  152. $out_detail = $grid->render("list2");
  153. ?>
  154. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  155. <html>
  156. <head>
  157.     <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/themes/start/jquery-ui.custom.css"></link>
  158.     <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/jqgrid/css/ui.jqgrid.css"></link> 
  159.    
  160.     <script src="../../lib/js/jquery.min.js" type="text/javascript"></script>
  161.     <script src="../../lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
  162.     <script src="../../lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script> 
  163.     <script src="../../lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
  164.     <script src="//cdn.jsdelivr.net/jquery.hotkeys/0.8b/jquery.hotkeys.js"></script>
  165. </head>
  166. <body>
  167.     <div style="margin:10px">
  168.     Master Detail Grid, on same page
  169.     <br>
  170.     <br>
  171.     <?php echo $out_master ?>
  172.     <br>
  173.     <br>
  174.     <?php echo $out_detail; ?>
  175.     </div>
  176.    
  177.     <script>
  178.     // insert key to add new row, tab to focus on save icon & press enter to save
  179.     $(document).bind('keyup', 'insert', function(){
  180.           jQuery('#list2_iladd').click();
  181.         });
  182.        
  183.     </script>  
  184. </body>
  185. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement