Guest User

Untitled

a guest
Jan 24th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.45 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. // include and create object
  14. include(PHPGRID_LIBPATH."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"] = "20";
  22. $col["frozen"] = true;
  23. $col["editable"] = true;
  24. $col["show"] = array("edit"=>true); // only show freezed column in edit dialog
  25. $cols[] = $col;
  26.  
  27. $col = array();
  28. $col["title"] = "Date";
  29. $col["name"] = "invdate";
  30. $col["frozen"] = true;
  31. $col["editable"] = true; // this column is editable
  32. $col["editoptions"] = array("size"=>20); // with default display of textbox with size 20
  33. $col["editrules"] = array("required"=>true); // required:true(false), number:true(false), minValue:val, maxValue:val
  34. $col["formatter"] = "date"; // format as date
  35. $col["show"] = array("edit"=>true); // only show freezed column in edit dialog
  36. $cols[] = $col;
  37.  
  38. $col = array();
  39. $col["title"] = "Total";
  40. $col["name"] = "total";
  41. $col["editable"] = true;
  42. // default render is textbox
  43. $col["editoptions"] = array("value"=>'10');
  44. $col["show"] = array("edit"=>false);
  45. $cols[] = $col;
  46.  
  47. $col = array();
  48. $col["title"] = "Closed";
  49. $col["name"] = "closed";
  50. $col["editable"] = true;
  51. $col["edittype"] = "checkbox"; // render as checkbox
  52. $col["editoptions"] = array("value"=>"Yes:No"); // with these values "checked_value:unchecked_value"
  53. $col["show"] = array("edit"=>false);
  54. $cols[] = $col;
  55.  
  56. $col = array();
  57. $col["title"] = "Note";
  58. $col["name"] = "note";
  59. $col["width"] = "400";
  60. $col["sortable"] = false; // this column is not sortable
  61. $col["search"] = false; // this column is not searchable
  62. $col["editable"] = true;
  63. $col["show"] = array("edit"=>false);
  64. $col["edittype"] = "textarea";
  65.  
  66. // set readmore class with textarea content
  67. $col["formatter"] = "function(cellval,options,rowdata){ return '<div class=\"readmore\">'+cellval+'</div>'; }";
  68. $col["unformat"] = "function(cellval,options,cell){ if(cellval == 'undefined') return ''; return jQuery(cell).children('div').html(); }";
  69. $cols[] = $col;
  70.  
  71. # Customization of Action column width and other properties
  72. $col = array();
  73. $col["title"] = "Action";
  74. $col["name"] = "act";
  75. $col["width"] = "150";
  76. $cols[] = $col;
  77.  
  78. $g = new jqgrid();
  79.  
  80. $grid["rowNum"] = 10; // by default 20
  81. $grid["sortname"] = 'id'; // by default sort grid by this field
  82. $grid["sortorder"] = "desc"; // ASC or DESC
  83. $grid["caption"] = "Invoice Data"; // caption of grid
  84.  
  85. $grid["width"] = "800"; // expand grid to screen width
  86. $grid["shrinkToFit"] = false; // dont shrink to fit on screen
  87. $grid["sortable"] = false; // it is required for freezed column feature
  88. $grid["loadComplete"] = "function(){ do_load(); }"; // connect onload event
  89.  
  90. $g->set_options($grid);
  91.  
  92. // disable all dialogs except edit
  93. $g->navgrid["param"]["edit"] = false;
  94. $g->navgrid["param"]["add"] = false;
  95. $g->navgrid["param"]["del"] = true;
  96. $g->navgrid["param"]["search"] = false;
  97. $g->navgrid["param"]["refresh"] = false;
  98.  
  99. // enable inline editing buttons
  100. $g->set_actions(array(
  101. "inline"=>true,
  102. "rowactions"=>true
  103. )
  104. );
  105.  
  106. // you can provide custom SQL query to display data
  107. $g->select_command = "SELECT i.id, invdate,
  108. i.note, i.total, i.closed FROM invheader i";
  109.  
  110. // this db table will be used for add,edit,delete
  111. $g->table = "invheader";
  112.  
  113. // pass the cooked columns to grid
  114. $g->set_columns($cols);
  115.  
  116. // generate grid output, with unique grid name as 'list1'
  117. $out = $g->render("list1");
  118.  
  119. ?>
  120. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  121. <html>
  122. <head>
  123. <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/themes/redmond/jquery-ui.custom.css"></link>
  124. <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/jqgrid/css/ui.jqgrid.css"></link>
  125.  
  126. <script src="../../lib/js/jquery.min.js" type="text/javascript"></script>
  127. <script src="../../lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
  128. <script src="../../lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
  129. <script src="../../lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
  130.  
  131. <script src="https://gitcdn.xyz/repo/jedfoster/Readmore.js/master/readmore.min.js" type="text/javascript"></script>
  132. </head>
  133. <body>
  134.  
  135. <style>
  136. /* fix for freeze column div position */
  137. .ui-jqgrid .editable {margin: 0px !important;}
  138.  
  139. .readmore {
  140. max-height: 2em; /* (4 * 1.5 = 6) */
  141. }
  142. </style>
  143.  
  144. <script>
  145. function normalize_height()
  146. {
  147. var grid = jQuery('#list1')[0];
  148.  
  149. // adjust height of rows (for multi line cell content)
  150. jQuery('.frozen-bdiv tr.jqgrow').each(function () {
  151. var h = jQuery('#'+jQuery.jgrid.jqID(this.id)).height();
  152.  
  153. if (jQuery.browser.chrome)
  154. h+=2;
  155.  
  156. jQuery(this).height(h);
  157. });
  158.  
  159. // sync scrolling position
  160. $(grid.grid.fbDiv).scrollTop($(grid.grid.bDiv).scrollTop());
  161. $(grid.grid.fbDiv).scrollLeft($(grid.grid.bDiv).scrollLeft());
  162.  
  163. // fix for height pixel
  164. if (jQuery.browser.msie)
  165. $(grid.grid.fbDiv).height($(grid.grid.bDiv).height()-16);
  166. else
  167. $(grid.grid.fbDiv).height($(grid.grid.bDiv).height()-18);
  168.  
  169. }
  170.  
  171. jQuery(document).ready(function(){
  172.  
  173. setTimeout(function(){
  174. jQuery('#list1').jqGrid('navButtonAdd', '#list1_pager',
  175. {
  176. 'caption' : 'Freeze Mode',
  177. 'buttonicon' : 'ui-icon-extlink',
  178. 'onClickButton': function()
  179. {
  180. var t;
  181. if (jQuery('div.frozen-bdiv').length == 0)
  182. {
  183. jQuery("#list1").jqGrid("setGridParam",{cellEdit : false});
  184. jQuery('#list1').jqGrid('setFrozenColumns');
  185. jQuery("#list1").jqGrid("setGridParam",{cellEdit : true});
  186.  
  187. // adjust height
  188. var grid = jQuery('#list1')[0];
  189. $(grid.grid.bDiv).scroll(function () { normalize_height(); });
  190. normalize_height();
  191.  
  192. // fix for ie
  193. if (jQuery.browser.msie)
  194. $(grid.grid.fhDiv).css("top","+=1");
  195.  
  196. // jQuery(".ui-icon-pencil, .ui-icon-disk, .ui-icon-cancel").click(function(){ setTimeout("normalize_height()",100); });
  197.  
  198. // sync frozen rows height
  199. jQuery('#list1').bind("mousedown keydown keyup",function(){
  200. t = setInterval("normalize_height()",100);
  201. setTimeout(function(){clearInterval(t);},1000);
  202. });
  203.  
  204. // remove frozen while add
  205. jQuery(".ui-icon-plus").click(function(){ jQuery('#list1').jqGrid('destroyFrozenColumns'); });
  206. }
  207. else
  208. {
  209. clearInterval(t);
  210. jQuery('#list1').jqGrid('destroyFrozenColumns');
  211. }
  212. },
  213. 'position': 'last'
  214. });
  215.  
  216. jQuery('#list1').jqGrid('destroyFrozenColumns').trigger('reloadGrid', [{current:true}]);
  217.  
  218. },200);
  219. });
  220.  
  221. function do_load()
  222. {
  223. jQuery('.readmore').readmore({
  224. blockCSS: 'display:block;',
  225. afterToggle: function(trigger, element, expanded) {
  226. if(! expanded) {
  227. $('html, body').animate( { scrollTop: element.offset().top }, {duration: 100 } );
  228. }
  229. }
  230. });
  231.  
  232. normalize_height();
  233. }
  234.  
  235. </script>
  236.  
  237. <div style="margin:10px">
  238. <?php echo $out?>
  239. </div>
  240. </body>
  241. </html>
Add Comment
Please, Sign In to add comment