Guest User

Untitled

a guest
May 28th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.02 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 2.0.0
  7.  * @license: see license.txt included in package
  8.  */
  9.  
  10. // todo: import/export settings https://phpgrid.desk.com/customer/portal/questions/16151684-export-and-import-report-settings-persistent- (24-2-16)
  11.  
  12. // include db config
  13. include_once("../../config.php");
  14.  
  15. // include and create object
  16. include(PHPGRID_LIBPATH."inc/jqgrid_dist.php");
  17.  
  18. // Database config file to be passed in phpgrid constructor
  19. $db_conf = array(  
  20.                     "type"      => PHPGRID_DBTYPE,
  21.                     "server"    => PHPGRID_DBHOST,
  22.                     "user"      => PHPGRID_DBUSER,
  23.                     "password"  => PHPGRID_DBPASS,
  24.                     "database"  => PHPGRID_DBNAME
  25.                 );
  26.                
  27. $g = new jqgrid($db_conf);
  28.  
  29.  
  30. $col = array();
  31. $col["title"] = "Id"; // caption of column
  32. $col["name"] = "id";
  33. $col["width"] = "10";
  34. $cols[] = $col;    
  35.        
  36. $col = array();
  37. $col["title"] = "Client";
  38. $col["name"] = "client_id";
  39. $col["dbname"] = "invheader.client_id"; // this is required as we need to search in name field, not id
  40. $col["width"] = "100";
  41. $col["align"] = "left";
  42. $col["search"] = true;
  43. $col["editable"] = true;
  44. $col["edittype"] = "select"; // render as select
  45. # fetch data from database, with alias k for key, v for value
  46. $str = $g->get_dropdown_values("select distinct client_id as k, name as v from clients");
  47. $col["editoptions"] = array("value"=>$str);
  48.  
  49. $col["stype"] = "select";
  50. $col["searchoptions"] = array("value"=>$str);
  51.  
  52. $col["editoptions"]["onload"]["sql"] = "select distinct client_id as k, name as v from clients";
  53.  
  54. $col["formatter"] = "select"; // display label, not value
  55. $cols[] = $col;
  56.  
  57. $col = array();
  58. $col["title"] = "Date";
  59. $col["name"] = "invdate";
  60. $col["width"] = "50";
  61. $col["editable"] = true; // this column is editable
  62. $col["editoptions"] = array("size"=>20); // with default display of textbox with size 20
  63. $col["editrules"] = array("required"=>true); // and is required
  64. $col["formatter"] = "date"; // format as date
  65. $col["search"] = false;
  66. $cols[] = $col;
  67.  
  68. $col = array();
  69. $col["title"] = "Amount";
  70. $col["name"] = "amount";
  71. $col["width"] = "50";
  72. $col["editable"] = true; // this column is editable
  73. $col["editoptions"] = array("size"=>20); // with default display of textbox with size 20
  74. $col["editrules"] = array("required"=>true); // and is required
  75.  
  76. $col["formatter"] = "number";
  77. $col["formatoptions"] = array("thousandsSeparator" => "",
  78.                                 "decimalSeparator" => ".",
  79.                                 "decimalPlaces" => 2);
  80.                                
  81. $cols[] = $col;
  82.  
  83. $col = array();
  84. $col["title"] = "Note";
  85. $col["name"] = "note";
  86. $col["width"] = "50";
  87. $col["editable"] = true; // this column is editable
  88. $col["editoptions"] = array("size"=>20); // with default display of textbox with size 20
  89. $col["hidedlg"] = true; // hide in column selection
  90. $cols[] = $col;
  91.  
  92. $grid["sortname"] = 'id'; // by default sort grid by this field
  93. $grid["sortorder"] = "desc"; // ASC or DESC
  94. $grid["caption"] = "Invoice Data"; // caption of grid
  95. $grid["multiselect"] = true; // allow you to multi-select through checkboxes
  96. $grid["autoresize"] = true; // allow you to multi-select through checkboxes
  97.  
  98. $grid["onAfterSave"] = "function(){ do_onload(); }";
  99.  
  100. $g->set_options($grid);
  101.  
  102. $g->set_actions(array( 
  103.                         "add"=>false, // allow/disallow add
  104.                         "edit"=>true, // allow/disallow edit
  105.                         "delete"=>true, // allow/disallow delete
  106.                         "showhidecolumns"=>true, // allow/disallow delete
  107.                         "rowactions"=>true, // show/hide row wise edit/del/save option
  108.                         "autofilter" => true, // show/hide autofilter for search
  109.                         "search" => "advance",
  110.                     )
  111.                 );
  112.  
  113. $g->select_command = "SELECT id, invdate, invheader.client_id, amount, note FROM invheader
  114.                         INNER JOIN clients on clients.client_id = invheader.client_id
  115.                         ";
  116.  
  117. // this db table will be used for add,edit,delete
  118. $g->table = "invheader";
  119.  
  120. // pass the cooked columns to grid
  121. $g->set_columns($cols);
  122.  
  123. $e["js_on_load_complete"] = "do_onload";
  124. $g->set_events($e);
  125.  
  126. // generate grid output, with unique grid name as 'list1'
  127. $out = $g->render("list1");
  128. ?>
  129. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  130. <html>
  131. <head>
  132.     <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/themes/redmond/jquery-ui.custom.css"></link>  
  133.     <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/jqgrid/css/ui.jqgrid.css"></link> 
  134.    
  135.     <script src="../../lib/js/jquery.min.js" type="text/javascript"></script>
  136.     <script src="../../lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
  137.     <script src="../../lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script> 
  138.     <script src="../../lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
  139.    
  140.     <script src="//cdn.jsdelivr.net/jstorage/0.1/jstorage.min.js" type="text/javascript"></script> 
  141.     <script src="//cdn.jsdelivr.net/json2/0.1/json2.min.js" type="text/javascript"></script>
  142.     <script src="//cdn.rawgit.com/gridphp/jqGridState/03b2bd484aecf8f47c810e7ba60606fe1a6fb7ec/jqGrid.state.js" type="text/javascript"></script>
  143. </head>
  144. <body>
  145.  
  146.     <script>
  147.     var opts = {
  148.         "stateOptions": {        
  149.                     storageKey: "gridState-list1",
  150.                     columns: true, // remember column chooser settings
  151.                     selection: true, // row selection
  152.                     expansion: true, // subgrid expansion
  153.                     filters: true, // subgrid expansion
  154.                     pager: true, // page number
  155.                     order: true // field ordering
  156.         }
  157.     };
  158.    
  159.     function do_onload(ids){
  160.  
  161.         var ids = jQuery('#list1').jqGrid('getDataIDs');
  162.         for (var x = 0; x < ids.length; x++) {
  163.  
  164.             var i = x;
  165.             var row =  $('#list1').getRowData(ids[x]);
  166.            
  167.             if (row.amount == '100.00' || parseInt(row.amount) == 100)
  168.             {
  169.                 jQuery('#list1 tr.jqgrow:eq('+i+')').css('background','inherit').css({'background-color':'#8CBF26'});
  170.             }
  171.         }
  172.        
  173.      }
  174.     </script>  
  175.  
  176.     <div style="margin:10px">
  177.     <?php echo $out?>
  178.     <br>
  179.     <button onclick="$('#list1').gridState().remove('gridState-list1');">Forget Settings</button>
  180.     </div>
  181.    
  182. </body>
  183. </html>
Add Comment
Please, Sign In to add comment