Advertisement
Guest User

Untitled

a guest
Mar 26th, 2015
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.63 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. // you can customize your own columns ...
  21.  
  22. $col = array();
  23. $col["title"] = "Id"; // caption of column
  24. $col["name"] = "id"; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
  25. $col["width"] = "10";
  26. # $col["hidden"] = true; // hide column by default
  27. $cols[] = $col;
  28.  
  29. $col = array();
  30. $col["title"] = "Client";
  31. $col["name"] = "name";
  32. $col["width"] = "100";
  33. $col["editable"] = false; // this column is not editable
  34. $col["align"] = "center"; // this column is not editable
  35. $col["search"] = false; // this column is not searchable
  36.  
  37. # $col["formatter"] = "image"; // format as image -- if data is image url e.g. http://<domain>/test.jpg
  38. # $col["formatoptions"] = array("width"=>'20',"height"=>'30'); // image width / height etc
  39.  
  40. $cols[] = $col;
  41.  
  42. $col = array();
  43. $col["title"] = "Note";
  44. $col["name"] = "note";
  45. # $col["width"] = "300"; // not specifying width will expand to fill space
  46. $col["sortable"] = false; // this column is not sortable
  47. $col["search"] = false; // this column is not searchable
  48. $col["editable"] = true;
  49. $col["edittype"] = "textarea"; // render as textarea on edit
  50. $col["editoptions"] = array("rows"=>2, "cols"=>20); // with these attributes
  51.  
  52. // don't show this column in list, but in edit/add mode
  53. $col["hidden"] = true;
  54. $col["editrules"] = array("edithidden"=>true);
  55.  
  56. $cols[] = $col;
  57.  
  58. $col = array();
  59. $col["title"] = "Date";
  60. $col["name"] = "invdate";
  61. $col["width"] = "50";
  62. $col["editable"] = true; // this column is editable
  63. $col["editoptions"] = array("size"=>20); // with default display of textbox with size 20
  64. $col["editrules"] = array("required"=>true); // required:true(false), number:true(false), minValue:val, maxValue:val
  65. $col["formatter"] = "datetime"; // format as date
  66. $cols[] = $col;
  67.  
  68.  
  69. $col = array();
  70. $col["title"] = "Total";
  71. $col["name"] = "total";
  72. $col["width"] = "50";
  73. $col["editable"] = true;
  74.  
  75. // default render is textbox
  76. $col["editoptions"] = array("value"=>'10');
  77.  
  78. // can be switched to select (dropdown)
  79. # $col["edittype"] = "select"; // render as select
  80. # $col["editoptions"] = array("value"=>'10:$10;20:$20;30:$30;40:$40;50:$50'); // with these values "key:value;key:value;key:value"
  81.  
  82. $cols[] = $col;
  83.  
  84. $col = array();
  85. $col["title"] = "Closed";
  86. $col["name"] = "closed";
  87. $col["width"] = "50";
  88. $col["editable"] = true;
  89. $col["edittype"] = "checkbox"; // render as checkbox
  90. $col["editoptions"] = array("value"=>"Yes:No"); // with these values "checked_value:unchecked_value"
  91. $col["editoptions"]["onclick"] = 'send_email(this)';
  92. $cols[] = $col;
  93.  
  94. # Custom made column to show link, must have default value as it's not db driven
  95. $col = array();
  96. $col["title"] = "Details";
  97. $col["name"] = "view_more";
  98. $col["width"] = "20";
  99. $col["align"] = "center";
  100. $col["search"] = false;
  101. $col["sortable"] = false;
  102. $col["link"] = "http://localhost/?id={id}"; // e.g. http://domain.com?id={id} given that, there is a column with $col["name"] = "id" exist
  103. $col["linkoptions"] = "target='_blank'"; // extra params with <a> tag
  104. $col["default"] = "View More"; // default link text
  105. $cols[] = $col;
  106.  
  107. # Customization of Action column width and other properties
  108. $col = array();
  109. $col["title"] = "Action";
  110. $col["name"] = "act";
  111. $col["width"] = "50";
  112. $cols[] = $col;
  113.  
  114. $g = new jqgrid();
  115.  
  116. // $grid["url"] = ""; // your paramterized URL -- defaults to REQUEST_URI
  117. $grid["rowNum"] = 10; // by default 20
  118. $grid["sortname"] = 'id'; // by default sort grid by this field
  119. $grid["sortorder"] = "desc"; // ASC or DESC
  120. $grid["caption"] = "Invoice Data"; // caption of grid
  121. $grid["autowidth"] = true; // expand grid to screen width
  122. $grid["multiselect"] = true; // allow you to multi-select through checkboxes
  123. $grid["scroll"] = true; // allow you to multi-select through checkboxes
  124.  
  125. // export XLS file
  126. // export to excel parameters
  127. $grid["export"] = array("format"=>"pdf", "filename"=>"my-file", "sheetname"=>"test");
  128.  
  129. // RTL support
  130. // $grid["direction"] = "rtl";
  131.  
  132. // $grid["cellEdit"] = true; // inline cell editing, like spreadsheet
  133.  
  134. $g->set_options($grid);
  135.  
  136. $g->set_actions(array(
  137. "add"=>true, // allow/disallow add
  138. "edit"=>true, // allow/disallow edit
  139. "delete"=>true, // allow/disallow delete
  140. "rowactions"=>true, // show/hide row wise edit/del/save option
  141. "export"=>true, // show/hide export to excel option
  142. "autofilter" => true, // show/hide autofilter for search
  143. "search" => "simple", // show single/multi field search condition (e.g. simple or advance)
  144. "showhidecolumns" => false // show single/multi field search condition (e.g. simple or advance)
  145. )
  146. );
  147.  
  148. // you can provide custom SQL query to display data
  149. $g->select_command = "SELECT * FROM (SELECT i.id, invdate , c.name,
  150. i.note, i.total, i.closed FROM invheader i
  151. INNER JOIN clients c ON c.client_id = i.client_id) o";
  152.  
  153. // this db table will be used for add,edit,delete
  154. $g->table = "invheader";
  155.  
  156. // pass the cooked columns to grid
  157. $g->set_columns($cols);
  158.  
  159. // generate grid output, with unique grid name as 'list1'
  160. $out = $g->render("list1");
  161. ?>
  162. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  163. <html>
  164. <head>
  165. <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/themes/redmond/jquery-ui.custom.css"></link>
  166. <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/jqgrid/css/ui.jqgrid.css"></link>
  167.  
  168. <script src="../../lib/js/jquery.min.js" type="text/javascript"></script>
  169. <script src="../../lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
  170. <script src="../../lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
  171. <script src="../../lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
  172. </head>
  173. <body>
  174. <div style="margin:10px">
  175. Refresh page to change themes randomly. You can also have your customized theme (jqueryui.com/themeroller).
  176. <br>
  177. <br>
  178. <?php echo $out?>
  179. </div>
  180. <script>
  181. function send_email(o)
  182. {
  183. var rowid = jQuery('#list1').jqGrid('getGridParam','selrow');
  184. if (o.checked)
  185. window.open("http://localhost/live_portal/library/leademail.php/?id="+rowid,"newwind","height=200,width=550");
  186. }
  187. </script>
  188. </body>
  189. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement