Guest User

Untitled

a guest
Jan 9th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.30 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["editable"] = true;
  27. $cols[] = $col;
  28.  
  29. $col = array();
  30. $col["title"] = "Date";
  31. $col["name"] = "invdate";
  32. $col["width"] = "50";
  33. $col["editable"] = true; // this column is editable
  34. $col["editoptions"] = array("size"=>20); // with default display of textbox with size 20
  35. $col["editrules"] = array("required"=>true, "edithidden"=>true); // and is required
  36. $col["formatter"] = "date"; // format as date
  37. $col["formatoptions"] = array("srcformat"=>'Y-m-d',"newformat"=>'d/m/Y'); // http://docs.jquery.com/UI/Datepicker/formatDate
  38. $cols[] = $col;
  39.  
  40. $col = array();
  41. $col["title"] = "Client";
  42. $col["name"] = "name";
  43. $col["width"] = "100";
  44. $col["editable"] = false; // this column is not editable
  45. $col["align"] = "center"; // this column is not editable
  46. $col["search"] = false; // this column is not searchable
  47. $cols[] = $col;
  48.  
  49. $col = array();
  50. $col["title"] = "Note";
  51. $col["name"] = "note";
  52. $col["sortable"] = false; // this column is not sortable
  53. $col["search"] = false; // this column is not searchable
  54. $col["editable"] = true;
  55. $col["edittype"] = "textarea"; // render as textarea on edit
  56. $col["editoptions"] = array("rows"=>2, "cols"=>20); // with these attributes
  57. $cols[] = $col;
  58.  
  59. $col = array();
  60. $col["title"] = "Total";
  61. $col["name"] = "total";
  62. $col["width"] = "50";
  63. $col["editable"] = true;
  64. $col["editoptions"]["dataInit"] = "function(o){edit_as_radio(o);}";
  65. $cols[] = $col;
  66.  
  67. /*
  68. $col = array();
  69. $col["title"] = "Closed";
  70. $col["name"] = "closed";
  71. $col["width"] = "50";
  72. $col["editable"] = true;
  73. $col["edittype"] = "checkbox"; // render as checkbox
  74. $col["editoptions"] = array("value"=>"1:0"); // with these values "checked_value:unchecked_value"
  75. $col["formatter"] = "checkbox";
  76. $cols[] = $col; */
  77.  
  78. $col = array();
  79. $col["title"] = "Closed";
  80. $col["name"] = "closed";
  81. $col["width"] = "50";
  82. $col["editable"] = true;
  83. $cols[] = $col;
  84.  
  85. $col = array();
  86. $col["title"] = "Action";
  87. $col["name"] = "act";
  88. $col["width"] = "70";
  89. $cols[] = $col;
  90.  
  91. $g = new jqgrid();
  92.  
  93. // $grid["url"] = ""; // your paramterized URL -- defaults to REQUEST_URI
  94. $grid["rowNum"] = 10; // by default 20
  95. $grid["sortname"] = 'id'; // by default sort grid by this field
  96. $grid["sortorder"] = "desc"; // ASC or DESC
  97. $grid["caption"] = "Invoice Data"; // caption of grid
  98. $grid["autowidth"] = true; // expand grid to screen width
  99. $grid["multiselect"] = true; // allow you to multi-select through checkboxes
  100. $grid["form"]["position"] = "center";
  101.  
  102. $g->set_options($grid);
  103.  
  104. $g->set_actions(array(
  105. "add"=>true, // allow/disallow add
  106. "edit"=>true, // allow/disallow edit
  107. "delete"=>true, // allow/disallow delete
  108. "rowactions"=>true, // show/hide row wise edit/del/save option
  109. "search" => "advance", // show single/multi field search condition (e.g. simple or advance)
  110. "showhidecolumns" => false
  111. )
  112. );
  113.  
  114. // you can provide custom SQL query to display data
  115. $g->select_command = "SELECT * FROM (SELECT i.id, invdate , c.name,
  116. i.note, i.total, i.closed FROM invheader i
  117. INNER JOIN clients c ON c.client_id = i.client_id) o";
  118.  
  119. // this db table will be used for add,edit,delete
  120. $g->table = "invheader";
  121.  
  122. // pass the cooked columns to grid
  123. $g->set_columns($cols);
  124.  
  125. // generate grid output, with unique grid name as 'list1'
  126. $out = $g->render("list1");
  127. ?>
  128. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  129. <html>
  130. <head>
  131. <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/themes/redmond/jquery-ui.custom.css"></link>
  132. <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/jqgrid/css/ui.jqgrid.css"></link>
  133. <script src="../../lib/js/jquery.min.js" type="text/javascript"></script>
  134. <script src="../../lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
  135. <script src="../../lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
  136. <script src="../../lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
  137. </head>
  138. <body>
  139. <div style="margin:10px">
  140. <?php echo $out?>
  141. </div>
  142.  
  143. <script>
  144. function edit_as_radio(o)
  145. {
  146. setTimeout(function(){
  147. jQuery(o).hide();
  148. jQuery(o).parent().append('<input title="0" type="radio" name="rd_closed" value="0" onclick="jQuery(\'#total, input[name=total].editable\').val(0);"/> 0 <input title="5" type="radio" name="rd_closed" value="5" onclick="jQuery(\'#total, input[name=total].editable\').val(5);"/> 5 <input title="10" type="radio" name="rd_closed" value="10" onclick="jQuery(\'#total, input[name=total].editable\').val(10);"/> 10');
  149. },100);
  150. }
  151. </script>
  152. <div style="margin:10px">
  153. <?php echo $out?>
  154. </div>
  155. </body>
  156. </html>
Add Comment
Please, Sign In to add comment