SHARE
TWEET

Untitled

a guest Jul 1st, 2015 349 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. $col["hidden"] = true;
  28. $cols[] = $col;
  29.  
  30. $col = array();
  31. $col["title"] = "Date";
  32. $col["name"] = "invdate";
  33. $col["width"] = "50";
  34. $col["editable"] = true; // this column is editable
  35. $col["editoptions"] = array("size"=>20, "defaultValue"=>"02/02/2013"); // with default display of textbox with size 20
  36. $col["editrules"] = array("required"=>true, "edithidden"=>true); // and is required
  37. $col["formatter"] = "date"; // format as date
  38. $col["formatoptions"] = array("srcformat"=>'Y-m-d',"newformat"=>'d/m/Y'); // http://docs.jquery.com/UI/Datepicker/formatDate
  39. $cols[] = $col;
  40.                
  41. $col = array();
  42. $col["title"] = "Client";
  43. $col["name"] = "name";
  44. $col["width"] = "100";
  45. $col["editable"] = false; // this column is not editable
  46. $col["align"] = "center"; // this column is not editable
  47. $col["search"] = false; // this column is not searchable
  48.  
  49. $cols[] = $col;
  50.  
  51. $col = array();
  52. $col["title"] = "Note";
  53. $col["name"] = "note";
  54. # $col["width"] = "300"; // not specifying width will expand to fill space
  55. $col["sortable"] = false; // this column is not sortable
  56. $col["search"] = false; // this column is not searchable
  57. $col["editable"] = true;
  58. $col["edittype"] = "textarea"; // render as textarea on edit
  59. $col["editoptions"] = array("rows"=>2, "cols"=>20); // with these attributes
  60. $cols[] = $col;
  61.  
  62. $col = array();
  63. $col["title"] = "Total";
  64. $col["name"] = "total";
  65. $col["width"] = "50";
  66. $col["editable"] = true;
  67. $col["formatter"] = "number";
  68.  
  69. // To mask password field, apply following attribs
  70. # $col["edittype"] = "password";
  71. # $col["formatter"] = "password";
  72.  
  73. // default render is textbox
  74. // $col["editoptions"] = array("value"=>'10');
  75.  
  76. // can be switched to select (dropdown)
  77. // $col["edittype"] = "select"; // render as select
  78. // $col["editoptions"] = array("value"=>'10:$10;20:$20;30:$30;40:$40;50:$50'); // with these values "key:value;key:value;key:value"
  79.  
  80. $cols[] = $col;
  81.  
  82. $col = array();
  83. $col["title"] = "Closed";
  84. $col["name"] = "closed";
  85. $col["width"] = "50";
  86.  
  87. $col["editable"] = true;
  88. $col["edittype"] = "checkbox"; // render as checkbox
  89. $col["editoptions"] = array("value"=>"1:0"); // with these values "checked_value:unchecked_value"
  90.  
  91. // custom formatter to show active checkbox
  92. $col["formatter"] = "function(cellvalue, options, rowObject){ return cboxFormatter(cellvalue, options, rowObject); }";
  93. $col["unformat"] = "function(cellvalue, options, cell){ return cboxUnFormat(cellvalue, options, cell);}";
  94.  
  95. $col["align"] = "center";
  96. $cols[] = $col;
  97.  
  98. $g = new jqgrid();
  99.  
  100. // $grid["url"] = ""; // your paramterized URL -- defaults to REQUEST_URI
  101. $grid["rowNum"] = 10; // by default 20
  102. $grid["sortname"] = 'id'; // by default sort grid by this field
  103. $grid["sortorder"] = "desc"; // ASC or DESC
  104. $grid["caption"] = "Invoice Data"; // caption of grid
  105. $grid["autowidth"] = true; // expand grid to screen width
  106. $grid["multiselect"] = true; // allow you to multi-select through checkboxes
  107. $grid["form"]["position"] = "center";
  108. $g->set_options($grid);
  109.  
  110. $g->set_actions(array( 
  111.                                                 "add"=>true, // allow/disallow add
  112.                                                 "edit"=>true, // allow/disallow edit
  113.                                                 "delete"=>true, // allow/disallow delete
  114.                                                 "view"=>true, // allow/disallow delete
  115.                                                 "rowactions"=>true, // show/hide row wise edit/del/save option
  116.                                                 "search" => "advance", // show single/multi field search condition (e.g. simple or advance)
  117.                                                 "showhidecolumns" => false
  118.                                         )
  119.                                 );
  120.  
  121. // you can provide custom SQL query to display data
  122. $g->select_command = "SELECT i.id, invdate , c.name,
  123.                                                 i.note, i.total, i.closed FROM invheader i
  124.                                                 INNER JOIN clients c ON c.client_id = i.client_id";
  125.  
  126. // you can provide custom SQL count query to display data
  127. $g->select_count = "SELECT count(*) as c FROM invheader i
  128.                                                 INNER JOIN clients c ON c.client_id = i.client_id";
  129.  
  130. // this db table will be used for add,edit,delete
  131. $g->table = "invheader";
  132.  
  133. // pass the cooked columns to grid
  134. $g->set_columns($cols);
  135.  
  136. // generate grid output, with unique grid name as 'list1'
  137. $out = $g->render("list1");
  138. ?>
  139. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  140. <html>
  141. <head>
  142.         <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/themes/redmond/jquery-ui.custom.css"></link>  
  143.         <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/jqgrid/css/ui.jqgrid.css"></link>     
  144.         <script src="../../lib/js/jquery.min.js" type="text/javascript"></script>
  145.         <script src="../../lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
  146.         <script src="../../lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>     
  147.         <script src="../../lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
  148. </head>
  149. <body>
  150.         <script>
  151.         function cboxFormatter(cellvalue, options, rowObject)
  152.         {
  153.                 if ( cellvalue == 1 )
  154.                         return '<input id="cbox'+options.rowId+'" type="checkbox" name="completed" value="'+options.rowId+'" onclick="updateRow('+options.rowId+',this.checked);" checked/> ';
  155.                 else
  156.                         return '<input id="cbox'+options.rowId+'" type="checkbox" name="completed" value="'+options.rowId+'" onclick="updateRow('+options.rowId+',this.checked);" /> ';      
  157.         }
  158.  
  159.         function cboxUnFormat(cellvalue, options, cell)
  160.         {
  161.                 return jQuery('input', cell).attr('value');
  162.         }
  163.  
  164.         function updateRow(id, checked)
  165.         {
  166.                 // call ajax to update date in db
  167.                 var request = {};
  168.                 request['oper'] = 'edit';
  169.                 request['id'] = id;
  170.                
  171.                 if (checked)
  172.                         request['closed'] = 1;
  173.                 else
  174.                         request['closed'] = 0;
  175.  
  176.                 var grid = jQuery('#list1');
  177.                 jQuery.ajax({
  178.                         url: grid.jqGrid('getGridParam','url'),
  179.                         dataType: 'html',
  180.                         data: request,
  181.                         type: 'POST',
  182.                         error: function(res, status) {
  183.                                 jQuery.jgrid.info_dialog(jQuery.jgrid.errors.errcap,'<div class=\"ui-state-error\">'+ res.responseText +'</div>',
  184.                                                 jQuery.jgrid.edit.bClose,{buttonalign:'right'});
  185.                         },
  186.                         success: function( data ) {
  187.                                 // reload grid for data changes
  188.                                 grid.jqGrid().trigger('reloadGrid',[{jqgrid_page:1}]);
  189.                         }
  190.                 });
  191.         }
  192.        
  193.         </script>
  194.         <div style="margin:10px">
  195.         Refresh page to change themes randomly. You can also have your customized theme (jqueryui.com/themeroller).
  196.         <br>
  197.         <br>
  198.         <?php echo $out?>
  199.         </div>
  200. </body>
  201. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top