Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2015
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.68 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. $g = new jqgrid();
  21.  
  22. // passed from parent grid
  23. $c_id = $_REQUEST["rowid"];
  24. if (empty($c_id)) $c_id = 0;
  25.  
  26. // you can customize your own columns ...
  27.  
  28. $col = array();
  29. $col["title"] = "Id"; // caption of column
  30. $col["name"] = "id"; // field name, must be exactly same as with SQL prefix or db field
  31. $col["width"] = "10";
  32. $cols[] = $col;
  33.  
  34. $col = array();
  35. $col["title"] = "Client Id";
  36. $col["name"] = "client_id";
  37. $col["width"] = "10";
  38. $col["editable"] = true;
  39. $col["hidden"] = true;
  40. $col["editoptions"] = array("defaultValue" => $c_id); // set default value
  41. $cols[] = $col;
  42.  
  43. $col = array();
  44. $col["title"] = "Date";
  45. $col["name"] = "invdate";
  46. $col["width"] = "50";
  47. $col["editable"] = true; // this column is editable
  48. $col["editoptions"] = array("size"=>20); // with default display of textbox with size 20
  49. $col["editrules"] = array("required"=>true); // and is required
  50. $cols[] = $col;
  51.  
  52. $col = array();
  53. $col["title"] = "Client";
  54. $col["name"] = "name";
  55. $col["width"] = "100";
  56. $col["editable"] = false; // this column is not editable
  57. $cols[] = $col;
  58.  
  59. $col = array();
  60. $col["title"] = "Note";
  61. $col["name"] = "note";
  62. $col["width"] = "100"; // not specifying width will expand to fill space
  63. $col["sortable"] = false; // this column is not sortable
  64. $col["search"] = false; // this column is not searchable
  65. $col["editable"] = true;
  66. // $col["edittype"] = "textarea"; // render as textarea on edit
  67. // $col["editoptions"] = array("rows"=>2, "cols"=>20); // with these attributes
  68. $col["edittype"] = "file"; // render as file
  69. $col["upload_dir"] = "temp"; // upload here
  70. $cols[] = $col;
  71.  
  72. $col = array();
  73. $col["title"] = "Total";
  74. $col["name"] = "total";
  75. $col["width"] = "50";
  76. $col["editable"] = true;
  77. $cols[] = $col;
  78.  
  79. $col = array();
  80. $col["title"] = "Closed";
  81. $col["name"] = "closed";
  82. $col["width"] = "50";
  83. $col["editable"] = true;
  84. $col["edittype"] = "checkbox"; // render as checkbox
  85. $col["editoptions"] = array("value"=>"Yes:No"); // with these values "checked_value:unchecked_value"
  86. $cols[] = $col;
  87.  
  88. // custom data (if passed) need to be filled in URL as query string ($_REQUEST);
  89. //$grid["url"] = "subgrid_detail.php?rowid=".$_REQUEST["rowid"]."&subgrid=".$_REQUEST["subgrid"]."&gender=".$_REQUEST["gender"];
  90.  
  91. // if no custom param, it is auto set inside lib -- dont need to set
  92. //$grid["url"] = "subgrid_detail.php?rowid=".$_REQUEST["rowid"]."&subgrid=".$_REQUEST["subgrid"];
  93.  
  94. $grid["sortname"] = 'id'; // by default sort grid by this field
  95. $grid["sortorder"] = "desc"; // ASC or DESC
  96. $grid["height"] = ""; // autofit height of subgrid
  97. $grid["caption"] = "Invoice Data"; // caption of grid
  98. $grid["autowidth"] = true; // expand grid to screen width
  99. $grid["multiselect"] = true; // allow you to multi-select through checkboxes
  100. $grid["export"] = array("filename"=>"my-file", "sheetname"=>"test"); // export to excel parameters
  101. $grid["subGrid"] = true;
  102. $grid["footerrow"] = true;
  103. $grid["subgridurl"] = "subgrid_sub_detail.php";
  104. // $grid["subgridparams"] = "closed"; // extra data for sub grid
  105.  
  106. // $grid["cellEdit"] = true;
  107. // to refresh parent after subgrid edit
  108. // $grid["afterSubmitCell"] = "function(serverresponse, rowid, cellname, value, iRow, iCol) { jQuery('#list1').trigger('reloadGrid',[{jqgrid_page:1}]); return [true, '']; }";
  109.  
  110. // reload parent after delete
  111. // $grid["delete_options"]["afterSubmit"] = "function(){jQuery('#list1').trigger('reloadGrid',[{jqgrid_page:1}]); return [true, ''];}";
  112.  
  113. // reload parent on update
  114. $grid["onAfterSave"] = "function(){ jQuery('#list1').trigger('reloadGrid',[{jqgrid_page:1}]); }";
  115.  
  116. // reload parent on add
  117. $grid["add_options"]["afterSubmit"] = "function(){jQuery('#list1').trigger('reloadGrid',[{jqgrid_page:1}]); return [true, ''];}";
  118.  
  119. $g->set_options($grid);
  120.  
  121. $g->set_actions(array(
  122. "add"=>true, // allow/disallow add
  123. "edit"=>true, // allow/disallow edit
  124. "delete"=>true, // allow/disallow delete
  125. "rowactions"=>true, // show/hide row wise edit/del/save option
  126. "export"=>true, // show/hide export to excel option
  127. "autofilter" => true, // show/hide autofilter for search
  128. "search" => "advance" // show single/multi field search condition (e.g. simple or advance)
  129. )
  130. );
  131.  
  132. // you can provide custom SQL query to display data
  133. $g->select_command = "select i.id, i.client_id, i.invdate, c.name,
  134. i.note, i.total, i.closed FROM invheader i
  135. INNER JOIN clients c ON c.client_id = i.client_id
  136. WHERE c.client_id = $c_id";
  137.  
  138. // this db table will be used for add,edit,delete
  139. $g->table = "invheader";
  140.  
  141. // pass the cooked columns to grid
  142. $g->set_columns($cols);
  143. // group columns header
  144. $g->set_group_header( array(
  145. "useColSpanStyle"=>true,
  146. "groupHeaders"=>array(
  147. array(
  148. "startColumnName"=>'invdate', // group starts from this column
  149. "numberOfColumns"=>2, // group span to next 2 columns
  150. "titleText"=>'Company Details' // caption of group header
  151. )
  152. )
  153. )
  154. );
  155.  
  156. // set footer row
  157. $e["js_on_load_complete"] = "grid_onload_sub";
  158. $g->set_events($e);
  159.  
  160. // generate grid output, with unique grid name as 'list1'
  161. $out = $g->render("sub1");
  162. ?>
  163. <div style="padding:5px">
  164. <?php echo $out; ?>
  165. </div>
  166.  
  167. <script>
  168. jQuery(document).ready(function(){
  169. jQuery('#<?php echo $g->id?>').jqGrid('navButtonAdd', '#<?php echo $g->id?>_pager',
  170. {
  171. 'caption' : 'Custom Button',
  172. 'buttonicon' : 'ui-icon-pencil',
  173. 'onClickButton': function()
  174. {
  175. // your custom JS code ...
  176. window.open("http://google.com");
  177. },
  178. 'position': 'last'
  179. });
  180. });
  181.  
  182. function grid_onload_sub(id)
  183. {
  184. var grid_id = '<?php echo $g->id?>';
  185. var grid = jQuery("#"+grid_id);
  186. var sum = grid.jqGrid('getCol', 'total', false, 'sum');
  187. sum = parseInt(sum).toFixed(2);
  188. grid.jqGrid('footerData','set', {total: sum+' &pound;'});
  189.  
  190. // apply access control in subgrid
  191. var rowids = grid.getDataIDs();
  192. var columnModels = grid.getGridParam().colModel;
  193. // check each visible row
  194. for (var i = 0; i < rowids.length; i++)
  195. {
  196. var rowid = rowids[i];
  197. var data = grid.getRowData(rowid);
  198. if (parseInt(data.total) > 100) // view only
  199. {
  200. jQuery("tr#"+rowid).addClass("not-editable-row");
  201. jQuery("tr#"+rowid+" td[aria-describedby$='_act']").html("-");
  202. }
  203.  
  204. }
  205. }
  206. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement