Guest User

Untitled

a guest
Jan 24th, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.32 KB | None | 0 0
  1. <?php
  2. /**
  3. * PHP Grid Component
  4. *
  5. * @author Abu Ghufran <[email protected]> - 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. $g = new jqgrid();
  17.  
  18. // set few params
  19. $grid["caption"] = "Loading data from Array";
  20. $grid["width"] = 700;
  21. $grid["autowidth"] = false;
  22. $grid["shrinkToFit"] = false;
  23. $grid["sortable"] = false;
  24. $grid["multiselect"] = true;
  25. $grid["footerrow"] = true;
  26. $grid["ignoreCase"] = true; // do case insensitive sorting
  27. $grid["loadComplete"] = "function(){ update_footer(); }";
  28. $grid["export"] = array("format"=>"pdf", "filename"=>"my-file", "heading"=>"Array Data", "orientation"=>"landscape", "paper"=>"a4");
  29. $g->set_options($grid);
  30.  
  31. $name = array('Pepsi 1.5 Litre', 'Sprite 1.5 Litre', 'Cocacola 1.5 Litre', 'Dew 1.5 Litre', 'Nestle 1.5 Litre');
  32. for ($i = 0; $i < 200; $i++)
  33. {
  34. $data[$i]['id'] = $i+1;
  35. $data[$i]['code'] = $name[rand(0, 4)][0].($i+5);
  36. $data[$i]['name'] = $name[rand(0, 4)];
  37.  
  38. // to simulate case insensitive sort
  39. $data[$i]['name'] = ($i%2)?strtoupper($data[$i]['name']):$data[$i]['name'];
  40.  
  41. $data[$i]['cost'] = rand(0, 100)." USD";
  42. $data[$i]['quantity'] = rand(0, 100);
  43. $data[$i]['discontinued'] = rand(0, 1);
  44. $data[$i]['email'] = 'buyer_'. rand(0, 100) .'@google.com';
  45. // $data[$i]['more_options'] = "<a class='fancybox' href='http://upload.wikimedia.org/wikipedia/commons/4/4a/Logo_2013_Google.png'><img height=25 src='http://ssl.gstatic.com/ui/v1/icons/mail/logo_default.png'></a>";
  46. }
  47.  
  48. // pass data in table param for local array grid display
  49. $g->table = $data; // blank array(); will show no records
  50.  
  51. // If you want to customize columns params
  52. $col = array();
  53. $col["title"] = "Id"; // caption of column
  54. $col["name"] = "id";
  55. $col["width"] = "60";
  56. $cols[] = $col;
  57.  
  58. $col = array();
  59. $col["title"] = "Code"; // caption of column
  60. $col["name"] = "code";
  61. $col["width"] = "40";
  62. $cols[] = $col;
  63.  
  64. $col = array();
  65. $col["title"] = "Name"; // caption of column
  66. $col["name"] = "name";
  67. $col["width"] = "120";
  68. $cols[] = $col;
  69.  
  70. $col = array();
  71. $col["title"] = "Cost"; // caption of column
  72. $col["name"] = "cost";
  73. $col["width"] = "100";
  74. $cols[] = $col;
  75.  
  76. $col = array();
  77. $col["title"] = "Quantity"; // caption of column
  78. $col["name"] = "quantity";
  79. $col["width"] = "100";
  80. $col["sorttype"] = "int";
  81. $cols[] = $col;
  82.  
  83. $col = array();
  84. $col["title"] = "Email"; // caption of column
  85. $col["name"] = "email";
  86. $col["width"] = "400";
  87. $col["formatter"] = "function(cellvalue, options, rowObject){ return my_custom_link(cellvalue, options, rowObject);}";
  88. $col["unformat"] = "function(cellvalue, options, rowObject){ return cellvalue; }";
  89. $cols[] = $col;
  90.  
  91. # Custom made column to show link, must have default value as it's not db driven
  92. $col = array();
  93. $col["title"] = "Details";
  94. $col["name"] = "more_options";
  95. $col["width"] = "30";
  96. $col["align"] = "center";
  97. $col["search"] = false;
  98. $col["sortable"] = false;
  99. $cols[] = $col;
  100.  
  101. $g->set_columns($cols);
  102.  
  103. $g->set_actions(array(
  104. "add"=>false, // allow/disallow add
  105. "edit"=>false, // allow/disallow edit
  106. "delete"=>false, // allow/disallow delete
  107. "view"=>true, // allow/disallow delete
  108. "rowactions"=>false, // show/hide row wise edit/del/save option
  109. "export"=>true, // show/hide export to excel option
  110. "autofilter" => true, // show/hide autofilter for search
  111. "search" => false // show single/multi field search condition (e.g. simple or advance)
  112. )
  113. );
  114.  
  115. // for using custom export
  116. // $e["on_export"] = array("custom_export", null, false);
  117. // $g->set_events($e);
  118.  
  119. // custom on_export callback function
  120. function custom_export($param)
  121. {
  122. $arr = $param["data"]; // the data for export
  123. $grid = $param["grid"]; // the complete grid object reference
  124.  
  125. // exporting data code
  126. }
  127.  
  128. // highlight cell, if defined cellclass OR cellcss
  129. $f = array();
  130. $f["column"] = "name";
  131. $f["op"] = "cn";
  132. $f["value"] = "Pepsi";
  133. $f["cellcss"] = "'background-color':'red'"; // this also work
  134. $f_conditions[] = $f;
  135.  
  136. // if nothing set in 'op' and 'value', it will set column formatting for all cell
  137. $f = array();
  138. $f["column"] = "quantity";
  139. $f["css"] = "'background-color':'#FBEC88', 'color':'green', 'font-weight':'bold'"; // must use (single quote ') with css attr and value
  140. $f_conditions[] = $f;
  141.  
  142. $g->set_conditional_css($f_conditions);
  143.  
  144.  
  145. // render grid
  146. $out = $g->render("list1");
  147. ?>
  148. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  149. <html>
  150. <head>
  151. <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/themes/redmond/jquery-ui.custom.css"></link>
  152. <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/jqgrid/css/ui.jqgrid.css"></link>
  153.  
  154. <script src="../../lib/js/jquery.min.js" type="text/javascript"></script>
  155. <script src="../../lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
  156. <script src="../../lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
  157. <script src="../../lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
  158.  
  159. <link type="text/css" rel="stylesheet" href="//cdn.jsdelivr.net/fancybox/2.1.4/jquery.fancybox.css" />
  160. <script type="text/javascript" src="//cdn.jsdelivr.net/fancybox/2.1.4/jquery.fancybox.js"></script>
  161.  
  162. </head>
  163. <body>
  164. <script>
  165. function my_custom_link(cellvalue, options, rowObject)
  166. {
  167. return '<a href="mailto:'+cellvalue+'">'+cellvalue+'</a>';
  168. }
  169. </script>
  170. <div style="margin:10px">
  171. <?php echo $out?>
  172. </div>
  173. <script>
  174. $(document).ready(function() {
  175. $('.fancybox').fancybox();
  176.  
  177. // add toolbar button
  178. setTimeout("add_tb()",100);
  179.  
  180. });
  181.  
  182. function add_tb(){
  183.  
  184. jQuery('#list1').jqGrid('navButtonAdd', '#list1_pager',
  185. {
  186. 'caption' : 'Find',
  187. 'buttonicon' : 'ui-icon-search',
  188. 'onClickButton': function()
  189. {
  190. // open search dialog via code
  191. $("#list1").jqGrid ('searchGrid');
  192. },
  193. 'position': 'last'
  194. });
  195. }
  196.  
  197. function update_footer()
  198. {
  199. var grid = $("#list1");
  200. sum = grid.jqGrid('getCol', 'quantity', false, 'sum');
  201. grid.jqGrid('footerData','set', {quantity: 'Sum: ' + sum.toFixed(2)}, false);
  202. }
  203. </script>
  204. </body>
  205. </html>
Add Comment
Please, Sign In to add comment