Guest User

Untitled

a guest
Mar 12th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.07 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. $g = new jqgrid($db_conf);
  26.  
  27. $grid["rowNum"] = 99999; // by default 20
  28. $grid["sortname"] = 'invdate'; // by default sort grid by this field
  29. $grid["sortorder"] = "asc"; // ASC or DESC
  30. $grid["caption"] = "Invoice Data"; // caption of grid
  31. $grid["autowidth"] = true; // expand grid to screen width
  32. $grid["multiselect"] = true; // allow you to multi-select through checkboxes
  33. $grid["reloadedit"] = true; // auto reload after editing
  34. $grid["footerrow"] = true; // Show footer row
  35. $grid["userDataOnFooter"] = true; // Fill footer row with userdata (with on_data_display event)
  36.  
  37. // to use footerdata without formatter, comment above and use this
  38. // $grid["loadComplete"] = 'function(){ var userData = jQuery("#list1").jqGrid("getGridParam","userData"); jQuery("#list1").jqGrid("footerData","set",userData,false); }';
  39.  
  40. $grid["grouping"] = true; //
  41. $grid["groupingView"] = array();
  42. $grid["groupingView"]["groupField"] = array("name"); // specify column name to group listing
  43. $grid["groupingView"]["groupColumnShow"] = array(true); // either show grouped column in list or not (default: true)
  44. $grid["groupingView"]["groupText"] = array("<b>{0} - {1} Item(s)</b>"); // {0} is grouped value, {1} is count in group
  45. $grid["groupingView"]["groupOrder"] = array("desc"); // show group in asc or desc order
  46. $grid["groupingView"]["groupDataSorted"] = array(true); // show sorted data within group
  47. $grid["groupingView"]["groupSummary"] = array(true); // work with summaryType, summaryTpl, see column: $col["name"] = "total";
  48. $grid["groupingView"]["groupCollapse"] = false; // Turn true to show group collapse (default: false)
  49. $grid["groupingView"]["showSummaryOnHide"] = true; // show summary row even if group collapsed (hide)
  50.  
  51. $g->set_options($grid);
  52.  
  53. $g->set_actions(array(
  54. "add"=>false, // allow/disallow add
  55. "edit"=>true, // allow/disallow edit
  56. "delete"=>true, // allow/disallow delete
  57. "rowactions"=>true, // show/hide row wise edit/del/save option
  58. "export"=>true, // show/hide export to excel option
  59. "autofilter" => true, // show/hide autofilter for search
  60. "search" => "advance" // show single/multi field search condition (e.g. simple or advance)
  61. )
  62. );
  63.  
  64. // you can provide custom SQL query to display data
  65. $g->select_command = "SELECT i.id, invdate, date_format(invdate,'%Y/%m') as month , c.name,
  66. i.note, i.total, i.closed FROM invheader i
  67. INNER JOIN clients c ON c.client_id = i.client_id";
  68.  
  69. // this db table will be used for add,edit,delete
  70. $g->table = "invheader";
  71.  
  72. // you can customize
  73. $col = array();
  74. $col["title"] = "Id"; // caption of column
  75. $col["name"] = "id";
  76. $col["width"] = "10";
  77. $cols[] = $col;
  78.  
  79. $col = array();
  80. $col["title"] = "Client";
  81. $col["name"] = "name";
  82. $col["width"] = "100";
  83. $col["editable"] = false; // this column is not editable
  84. $col["search"] = false; // this column is not searchable
  85.  
  86. // to show some image with grouped column
  87. // $col["formatter"] = "function(cellval,options,rowdata){ return '<img src=\"'+rowdata['note']+'\" /><div>'+cellval+'</div>'; }";
  88. // $col["unformat"] = "function(cellval,options,cell){ return $('div', cell).text(); }";
  89.  
  90. $cols[] = $col;
  91.  
  92. $col = array();
  93. $col["title"] = "Note";
  94. $col["name"] = "note";
  95. $col["sortable"] = false; // this column is not sortable
  96. $col["search"] = false; // this column is not searchable
  97. $col["editable"] = true;
  98. $col["edittype"] = "textarea"; // render as textarea on edit
  99. $col["editoptions"] = array("rows"=>2, "cols"=>20); // with these attributes
  100. $cols[] = $col;
  101.  
  102. $col = array();
  103. $col["title"] = "Date";
  104. $col["name"] = "invdate";
  105. $col["width"] = "50";
  106. $col["editable"] = true; // this column is editable
  107. $col["editoptions"] = array("size"=>20); // with default display of textbox with size 20
  108. $col["editrules"] = array("required"=>true); // and is required
  109. $col["formatter"] = "date"; // format as date
  110. $cols[] = $col;
  111.  
  112. $col = array();
  113. $col["title"] = "Month";
  114. $col["name"] = "month";
  115. $col["width"] = "50";
  116. $col["editable"] = false; // this column is editable
  117. $cols[] = $col;
  118.  
  119. $col = array();
  120. $col["title"] = "Total";
  121. $col["name"] = "total";
  122. $col["width"] = "50";
  123. $col["editable"] = true;
  124. $col["summaryType"] = "sum"; // available grouping fx: sum, count, min, max, avg
  125. $col["summaryTpl"] = '<b>Total: ${0}</b>'; // display html for summary row - work when "groupSummary" is set true. search below
  126. $cols[] = $col;
  127.  
  128. $col = array();
  129. $col["title"] = "Closed";
  130. $col["name"] = "closed";
  131. $col["width"] = "50";
  132. $col["editable"] = true;
  133. $col["edittype"] = "checkbox"; // render as checkbox
  134. $col["editoptions"] = array("value"=>"Yes:No"); // with these values "checked_value:unchecked_value"
  135. $cols[] = $col;
  136.  
  137. // pass the cooked columns to grid
  138. $g->set_columns($cols);
  139.  
  140. // generate footer data for grand sum
  141. $e["on_data_display"] = array("filter_display", null, true);
  142. $g->set_events($e);
  143.  
  144. function filter_display($data)
  145. {
  146. // grand sum total and show in footer user data
  147. $total = 0;
  148. foreach($data["params"] as &$d)
  149. {
  150. $total += $d["total"];
  151. }
  152.  
  153. $data["params"]["userdata"] = array("note"=>"Grand Summary","total"=>"Total: $".$total);
  154. }
  155.  
  156. $grid_id = "list1";
  157. // generate grid output, with unique grid name as 'list1'
  158. $out = $g->render($grid_id);
  159. ?>
  160. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  161. <html>
  162. <head>
  163. <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/themes/redmond/jquery-ui.custom.css"></link>
  164. <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/jqgrid/css/ui.jqgrid.css"></link>
  165.  
  166. <script src="../../lib/js/jquery.min.js" type="text/javascript"></script>
  167. <script src="../../lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
  168. <script src="../../lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
  169. <script src="../../lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
  170. </head>
  171. <body>
  172. <style>
  173. /* change color of group text */
  174. .jqgroup b {
  175. color: navy;
  176. }
  177.  
  178. .ui-jqgrid tr.jqgroup td
  179. {
  180. background-color: lightyellow;
  181. }
  182. </style>
  183. <div style="margin:10px">
  184. Dynamic Group By:
  185. <select class="chngroup">
  186. <?php foreach($cols as $c) { ?>
  187. <option value="<?php echo $c["name"] ?>"><?php echo $c["title"] ?></option>
  188. <?php } ?>
  189. <option value="clear">Clear</option>
  190. </select>
  191. <button id="toggleGroup">Toggle Grouping</button>
  192. <script>
  193. jQuery(window).load(function()
  194. {
  195. // show dropdown in toolbar
  196. jQuery('.navtable tr').append('<td><div style="padding-left: 5px; padding-top:0px; float:left"><select style="height:24px" class="chngroup"><option value="clear" >-Group-</option><?php foreach($cols as $c) { if($c["title"] !='Action'){?><option value="<?php echo $c["name"] ?>" <?php echo ($c["name"]=="role")?"selected":"" ?>><?php echo $c["title"] ?></option><?php }} ?></select></div></td>');
  197.  
  198. var grid_id = '<?php echo $g->id ?>';
  199.  
  200. jQuery(".chngroup").change(function()
  201. {
  202. var vl = jQuery(this).val();
  203. if(vl)
  204. {
  205. if(vl == "clear")
  206. jQuery("#"+grid_id).jqGrid('groupingRemove',true);
  207. else
  208. jQuery("#"+grid_id).jqGrid('groupingGroupBy',vl);
  209. }
  210. });
  211.  
  212. // http://www.trirand.com/jqgridwiki/doku.php?id=wiki:grouping#methods
  213. jQuery("#toggleGroup").click(function()
  214. {
  215. jQuery("."+grid_id+"ghead_0").each(function(){
  216. jQuery("#"+grid_id).jqGrid('groupingToggle',jQuery(this).attr('id'));
  217. });
  218. });
  219. });
  220. </script>
  221. <br>
  222. <br>
  223. <?php echo $out?>
  224. </div>
  225. </body>
  226. </html>
Add Comment
Please, Sign In to add comment