Guest User

Untitled

a guest
Sep 3rd, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.28 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. $opt = array();
  28. $opt["rowNum"] = 10; // by default 20
  29. $opt["sortname"] = 'id'; // by default sort grid by this field
  30. $opt["sortorder"] = "desc"; // ASC or DESC
  31. $opt["caption"] = "Invoice Data"; // caption of grid
  32. $opt["autowidth"] = true; // expand grid to screen width
  33. $opt["multiselect"] = true; // allow you to multi-select through checkboxes
  34.  
  35. // export XLS file
  36. // export to excel parameters
  37. $opt["export"] = array("format"=>"pdf", "filename"=>"my-file", "sheetname"=>"test");
  38.  
  39. $g->set_options($opt);
  40.  
  41. $g->set_actions(array(
  42. "add"=>false, // allow/disallow add
  43. "edit"=>true, // allow/disallow edit
  44. "delete"=>true, // allow/disallow delete
  45. "rowactions"=>true, // show/hide row wise edit/del/save option
  46. "export"=>true, // show/hide export to excel option
  47. "autofilter" => true, // show/hide autofilter for search
  48. "search" => "advance" // show single/multi field search condition (e.g. simple or advance)
  49. )
  50. );
  51.  
  52. // you can provide custom SQL query to display data
  53. $g->select_command = "SELECT * FROM (SELECT i.id, invdate , c.name,
  54. i.note, i.total, i.closed FROM invheader i
  55. INNER JOIN clients c ON c.client_id = i.client_id) o";
  56.  
  57. // this db table will be used for add,edit,delete
  58. $g->table = "invheader";
  59.  
  60. // you can customize your own columns ...
  61. $col = array();
  62. $col["title"] = "Id"; // caption of column
  63. $col["name"] = "id"; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
  64. $col["width"] = "10";
  65. # $col["hidden"] = true; // hide column by default
  66. $cols[] = $col;
  67.  
  68. $col = array();
  69. $col["title"] = "Client";
  70. $col["name"] = "name";
  71. $col["width"] = "100";
  72. $col["editable"] = false; // this column is not editable
  73. $col["search"] = false; // this column is not searchable
  74.  
  75. # $col["formatter"] = "image"; // format as image -- if data is image url e.g. http://<domain>/test.jpg
  76. # $col["formatoptions"] = array("width"=>'20',"height"=>'30'); // image width / height etc
  77.  
  78. $cols[] = $col;
  79.  
  80. $col = array();
  81. $col["title"] = "Note";
  82. $col["name"] = "note";
  83. $col["width"] = "100"; // not specifying width will expand to fill space
  84. $col["sortable"] = false; // this column is not sortable
  85. $col["search"] = false; // this column is not searchable
  86. $col["editable"] = true;
  87. $col["edittype"] = "textarea"; // render as textarea on edit
  88. $col["editoptions"] = array("rows"=>2, "cols"=>20); // with these attributes
  89.  
  90. // don't show this column in list, but in edit/add mode
  91. $col["hidden"] = true;
  92. $col["editrules"] = array("edithidden"=>true);
  93.  
  94. $cols[] = $col;
  95.  
  96. $col = array();
  97. $col["title"] = "Date";
  98. $col["name"] = "invdate";
  99. $col["width"] = "50";
  100. $col["editable"] = true; // this column is editable
  101. $col["editoptions"] = array("size"=>20); // with default display of textbox with size 20
  102. $col["editrules"] = array("required"=>true); // required:true(false), number:true(false), minValue:val, maxValue:val
  103. $col["formatter"] = "date"; // format as date
  104. $cols[] = $col;
  105.  
  106.  
  107. $col = array();
  108. $col["title"] = "Total";
  109. $col["name"] = "total";
  110. $col["width"] = "50";
  111. $col["editable"] = true;
  112.  
  113. // default render is textbox
  114. $col["editoptions"] = array("value"=>'10');
  115.  
  116. // can be switched to select (dropdown)
  117. # $col["edittype"] = "select"; // render as select
  118. # $col["editoptions"] = array("value"=>'10:$10;20:$20;30:$30;40:$40;50:$50'); // with these values "key:value;key:value;key:value"
  119.  
  120. $cols[] = $col;
  121.  
  122. $col = array();
  123. $col["title"] = "Closed";
  124. $col["name"] = "closed";
  125. $col["width"] = "50";
  126. $col["editable"] = true;
  127. $col["edittype"] = "checkbox"; // render as checkbox
  128. $col["editoptions"] = array("value"=>"Yes:No"); // with these values "checked_value:unchecked_value"
  129. $cols[] = $col;
  130.  
  131. # Custom made column to show link, must have default value as it's not db driven
  132. $col = array();
  133. $col["title"] = "Details";
  134. $col["name"] = "more_options";
  135. $col["width"] = "50";
  136. $col["align"] = "center";
  137. $col["search"] = false;
  138. $col["sortable"] = false;
  139. $buttons_html = "<a target='_blank' href='mylink.php' class='myclass'>DashButton Gambio!</a>";
  140. $col["default"] = $buttons_html;
  141.  
  142. $cols[] = $col;
  143.  
  144. // pass the cooked columns to grid
  145. $g->set_columns($cols);
  146.  
  147. // generate grid output, with unique grid name as 'list1'
  148. $out = $g->render("list1");
  149. ?>
  150. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  151. <html>
  152. <head>
  153. <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/themes/redmond/jquery-ui.custom.css"></link>
  154. <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/jqgrid/css/ui.jqgrid.css"></link>
  155.  
  156. <script src="../../lib/js/jquery.min.js" type="text/javascript"></script>
  157. <script src="../../lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
  158. <script src="../../lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
  159. <script src="../../lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
  160. </head>
  161. <body>
  162. <div style="margin:10px">
  163. <?php echo $out?>
  164. </div>
  165.  
  166. <style>
  167. a.myclass
  168. {
  169. border-top: 1px solid #96d1f8;
  170. background: #65a9d7;
  171. background: -webkit-gradient(linear, left top, left bottom, from(#3e779d), to(#65a9d7));
  172. background: -webkit-linear-gradient(top, #3e779d, #65a9d7);
  173. background: -moz-linear-gradient(top, #3e779d, #65a9d7);
  174. background: -ms-linear-gradient(top, #3e779d, #65a9d7);
  175. background: -o-linear-gradient(top, #3e779d, #65a9d7);
  176. padding: 3.5px 7px;
  177. -webkit-border-radius: 17px;
  178. -moz-border-radius: 17px;
  179. border-radius: 17px;
  180. -webkit-box-shadow: rgba(0,0,0,1) 0 1px 0;
  181. -moz-box-shadow: rgba(0,0,0,1) 0 1px 0;
  182. box-shadow: rgba(0,0,0,1) 0 1px 0;
  183. text-shadow: rgba(0,0,0,.4) 0 1px 0;
  184. color: white !important;
  185. font-size: 14px;
  186. font-family: Georgia, Serif;
  187. text-decoration: none;
  188. vertical-align: middle;
  189. }
  190. a.myclass:hover
  191. {
  192. border-top: 1px solid #96d1f8;
  193. background: #65a9d7;
  194. background: -webkit-gradient(linear, left top, left bottom, from(#3e779d), to(#65a9d7));
  195. background: -webkit-linear-gradient(top, #3e779d, #65a9d7);
  196. background: -moz-linear-gradient(top, #3e779d, #65a9d7);
  197. background: -ms-linear-gradient(top, #3e779d, #65a9d7);
  198. background: -o-linear-gradient(top, #3e779d, #65a9d7);
  199. padding: 3.5px 7px;
  200. -webkit-border-radius: 17px;
  201. -moz-border-radius: 17px;
  202. border-radius: 17px;
  203. -webkit-box-shadow: rgba(0,0,0,1) 0 1px 0;
  204. -moz-box-shadow: rgba(0,0,0,1) 0 1px 0;
  205. box-shadow: rgba(0,0,0,1) 0 1px 0;
  206. text-shadow: rgba(0,0,0,.4) 0 1px 0;
  207. color: white !important;
  208. font-size: 16px;
  209. font-family: Georgia, Serif;
  210. text-decoration: none;
  211. vertical-align: middle;
  212. }
  213. </style>
  214. </body>
  215. </html>
Add Comment
Please, Sign In to add comment