daily pastebin goal
23%
SHARE
TWEET

Untitled

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