Advertisement
Guest User

Untitled

a guest
Jan 21st, 2015
489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.19 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. $conn = mysql_connect("localhost", "root", "");
  11. mysql_select_db("griddemo");
  12.  
  13. $base_path = strstr(realpath("."),"demos",true)."lib/";
  14. include($base_path."inc/jqgrid_dist.php");
  15.  
  16. // you can customize your own columns ...
  17.  
  18. $col = array();
  19. $col["title"] = "Id"; // caption of column
  20. $col["name"] = "id"; // grid column name, must be exactly same as returned column-name from sql (tablefield or field-alias)
  21. $col["width"] = "10";
  22. $cols[] = $col;
  23.  
  24. $col = array();
  25. $col["title"] = "Client";
  26. $col["name"] = "name";
  27. $col["width"] = "100";
  28. $col["editable"] = false; // this column is not editable
  29. $col["search"] = false; // this column is not searchable
  30.  
  31. $cols[] = $col;
  32.  
  33. $col = array();
  34. $col["title"] = "Date";
  35. $col["name"] = "invdate";
  36. $col["width"] = "50";
  37. $col["editable"] = true; // this column is editable
  38. $col["editoptions"] = array("size"=>20); // with default display of textbox with size 20
  39. $col["editrules"] = array("required"=>true); // required:true(false), number:true(false), minValue:val, maxValue:val
  40. $col["formatter"] = "date"; // format as date
  41. $cols[] = $col;
  42.  
  43. $col = array();
  44. $col["title"] = "Total";
  45. $col["name"] = "total";
  46. $col["width"] = "50";
  47. $col["editable"] = true;
  48. // default render is textbox
  49. $col["editoptions"] = array("value"=>'10');
  50.  
  51. $cols[] = $col;
  52.  
  53. $col = array();
  54. $col["title"] = "Closed";
  55. $col["name"] = "closed";
  56. $col["width"] = "50";
  57. $col["editable"] = true;
  58. $col["edittype"] = "checkbox"; // render as checkbox
  59. $col["editoptions"] = array("value"=>"Yes:No"); // with these values "checked_value:unchecked_value"
  60. $cols[] = $col;
  61.  
  62. # Custom made column to show link, must have default value as it's not db driven
  63. $col = array();
  64. $col["title"] = "Logo";
  65. $col["name"] = "logo";
  66. $col["width"] = "40";
  67. $col["align"] = "center";
  68. $col["search"] = false;
  69. $col["sortable"] = false;
  70. # class='fancybox' to open image in fancybox
  71. $col["default"] = "<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>";
  72. $cols[] = $col;
  73.  
  74. # Custom made column to show link, must have default value as it's not db driven
  75. $col = array();
  76. $col["title"] = "Details";
  77. $col["name"] = "more_options";
  78. $col["width"] = "30";
  79. $col["align"] = "center";
  80. $col["search"] = false;
  81. $col["sortable"] = false;
  82. $buttons_html = "<a target='_blank' class='fancybox' data-fancybox-type='iframe' href='http://jqgrid/dev/demos/editing/index.php' style='text-decoration:none; white-space:none; border:1px solid gray; padding:2px; position:relative; width:25px; color:red'>Buy</a> <a target='_blank' href='http://www.google.com?id={id}' style='text-decoration:none; white-space:none; border:1px solid gray; padding:2px; position:relative; width:25px; color:green'>Try</a>";
  83. $col["default"] = $buttons_html;
  84. $cols[] = $col;
  85.  
  86. $g = new jqgrid();
  87.  
  88. $grid["rowNum"] = 10; // by default 20
  89. $grid["sortname"] = 'id'; // by default sort grid by this field
  90. $grid["sortorder"] = "desc"; // ASC or DESC
  91. $grid["caption"] = "Invoice Data"; // caption of grid
  92. $grid["autowidth"] = true; // expand grid to screen width
  93.  
  94. $g->set_options($grid);
  95.  
  96. $g->set_actions(array(
  97. "add"=>true, // allow/disallow add
  98. "edit"=>true, // allow/disallow edit
  99. "delete"=>true, // allow/disallow delete
  100. "rowactions"=>true, // show/hide row wise edit/del/save option
  101. "export"=>true, // show/hide export to excel option
  102. "autofilter" => true, // show/hide autofilter for search
  103. "search" => "advance" // show single/multi field search condition (e.g. simple or advance)
  104. )
  105. );
  106.  
  107. // you can provide custom SQL query to display data
  108. $g->select_command = "SELECT * FROM (SELECT i.id, invdate , c.name,
  109. i.note, i.total, i.closed FROM invheader i
  110. INNER JOIN clients c ON c.client_id = i.client_id) o";
  111.  
  112. // this db table will be used for add,edit,delete
  113. $g->table = "invheader";
  114.  
  115. // pass the cooked columns to grid
  116. $g->set_columns($cols);
  117.  
  118. $e["js_on_load_complete"] = "grid_onload";
  119. $g->set_events($e);
  120.  
  121. // generate grid output, with unique grid name as 'list1'
  122. $out = $g->render("list1");
  123. ?>
  124. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  125. <html>
  126. <head>
  127. <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/themes/redmond/jquery-ui.custom.css"></link>
  128. <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/jqgrid/css/ui.jqgrid.css"></link>
  129.  
  130. <script src="../../lib/js/jquery.min.js" type="text/javascript"></script>
  131. <script src="../../lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
  132. <script src="../../lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
  133. <script src="../../lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
  134.  
  135. <!-- Add fancyBox main JS and CSS files -->
  136. <link type="text/css" rel="stylesheet" href="//cdn.jsdelivr.net/fancybox/2.1.4/jquery.fancybox.css" />
  137. <script type="text/javascript" src="//cdn.jsdelivr.net/fancybox/2.1.4/jquery.fancybox.js"></script>
  138.  
  139. </head>
  140. <body>
  141.  
  142.  
  143. <script>
  144. // on dbl click event on list
  145. var opts = {
  146. 'ondblClickRow': function (id) {
  147. window.open("edit.php?id="+id)
  148. }
  149. };
  150. </script>
  151.  
  152. <div style="margin:10px">
  153. <?php echo $out?>
  154. </div>
  155.  
  156. <script>
  157.  
  158. // custom edit button on grid
  159. jQuery(document).ready(function(){
  160.  
  161. jQuery('#list1').jqGrid('navButtonAdd', '#list1_pager',
  162. {
  163. 'caption' : 'Edit',
  164. 'buttonicon' : 'ui-icon-pencil',
  165. 'onClickButton': function()
  166. {
  167. // for selected rows
  168. var selectedRow = jQuery('#list1').jqGrid('getGridParam','selrow');
  169.  
  170. if (selectedRow.length == 0)
  171. {
  172. return;
  173. }
  174.  
  175.  
  176. var name = jQuery('#list1').jqGrid('getCell', selectedRow, 'name');
  177. var date = jQuery('#list1').jqGrid('getCell', selectedRow, 'invdate');
  178.  
  179. window.open("edit.php?id="+selectedRow+"&name="+name+"&date="+date);
  180. },
  181. 'position': 'last'
  182. });
  183. });
  184.  
  185. </script>
  186. </body>
  187. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement