Advertisement
caloyiv

PHPGrid Dropdown Problem

Oct 16th, 2014
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.81 KB | None | 0 0
  1. <?php require_once('../../includes/initialize.php');?>
  2. <?php
  3. /**
  4.  * PHP Grid Component
  5.  *
  6.  * @author Abu Ghufran <gridphp@gmail.com> - http://www.phpgrid.org
  7.  * @version 1.5.2
  8.  * @license: see license.txt included in package
  9.  */
  10.  
  11. // second grid
  12. $grid = new jqgrid();
  13.  
  14. $opt["caption"] = "Remittance Data";
  15. //set columns
  16. ## ------------------ ##
  17. ## CLIENT SIDE EVENTS ##
  18. ## ------------------ ##
  19. // just set the JS function name (should exist)
  20. //$opt["onSelectRow"] = "function(ids) { do_onselect(ids); }";
  21. $opt["loadComplete"] = "function(ids) { do_onload(ids); }";
  22.  
  23. // to simulate, comment theh onselectrow event line
  24. // $opt["ondblClickRow"] = "function(id,row,col) { do_ondblclick(id,row,col); }";
  25.  
  26. $grid->set_options($opt);
  27.  
  28.  
  29. $grid->table = "remittance";
  30. $g->select_command = "SELECT remittance_id, remittance.salesman_id, date, amount FROM remittance INNER JOIN salesman on salesman.salesman_id = remittance.salesman_id";
  31.  
  32. $col = array();
  33. $col["title"] = "ID"; // caption of column
  34. $col["name"] = "remittance_id"; // grid column name, same as db field or alias from sql
  35. $col["width"] = "5";
  36. $col["editable"] = false;  
  37. $col["search"] = false; // this column is not searchable
  38. $cols[] = $col;
  39.  
  40. $col = array();
  41. $col["title"] = "Salesman"; // caption of column
  42. $col["name"] = "salesman_id"; // grid column name, same as db field or alias from sql
  43. $col["dbname"] = "salesman"; // this is required as we need to search in name field, not id
  44. $col["width"] = "20";
  45. $col["search"] = true; // this column is not searchable
  46. $col["editable"] = true;  
  47. $col["edittype"] = "select"; // render as select
  48. # fetch data from database, with alias k for key, v for value
  49. $str = $g->get_dropdown_values("select distinct salesman_id as k, salesman_name as v from salesman");
  50. $col["editoptions"] = array("value"=>":;".$str);
  51. $col["formatter"] = "select"; // display label, not value
  52. $cols[] = $col;
  53.  
  54. $col = array();
  55. $col["title"] = "Date"; // caption of column
  56. $col["name"] = "date"; // grid column name, same as db field or alias from sql
  57. $col["width"] = "20";
  58. $col["hidden"] = false;
  59. $col["editable"] = true;
  60. $col["formatter"] = "date";
  61. $cols[] = $col;
  62.  
  63. $col = array();
  64. $col["title"] = "Amount"; // caption of column
  65. $col["name"] = "amount"; // grid column name, same as db field or alias from sql
  66. $col["width"] = "20";
  67. $col["hidden"] = false;
  68. $col["editable"] = true;
  69. $cols[] = $col;
  70.  
  71. $grid->set_columns($cols);
  72.  
  73.  
  74. ## ------------------ ##
  75. ## SERVER SIDE EVENTS ##
  76. ## ------------------ ##
  77.  
  78. // params are array(<function-name>,<class-object> or <null-if-global-func>,<continue-default-operation>)
  79. // if you pass last argument as true, functions will act as a data filter, and insert/update will be performed by grid
  80. $e["on_insert"] = array("add_remittance", null, true);
  81. $e["on_update"] = array("update_remittance", null, true);
  82. $e["on_delete"] = array("delete_remittance", null, true);
  83. $e["on_after_insert"] = array("after_inset_remittance", null, true); // return last inserted id for further working
  84. $e["on_data_display"] = array("filter_display_remittance", null, true);
  85. $grid->set_events($e);
  86. $grid->set_actions(array(    
  87.                         "add"=>true, // allow/disallow add
  88.                         "edit"=>true, // allow/disallow edit
  89.                         "delete"=>false, // allow/disallow delete
  90.                         "inlineadd"=>false, // allow/disallow delete
  91.                         "rowactions"=>false, // show/hide row wise edit/del/save option
  92.                         "view"=>true, // allow/disallow view
  93.                         "autofilter" => true, // show/hide autofilter for search
  94.                         "search" => "advance" // show single/multi field search condition (e.g. simple or advance)
  95.                     )
  96.                 );
  97.                
  98. function update_remittance($data)
  99. {
  100.    
  101. }
  102.  
  103. function delete_remittance($data)
  104. {
  105.    
  106. }
  107.  
  108. function add_remittance($data)
  109. {
  110.    
  111. }
  112.  
  113. function after_insert_remittance($data)
  114. {  
  115.    
  116. }
  117.  
  118.  
  119. /**
  120.  * Just update the passed argument, as it is passed by reference
  121.  * Changes will be reflected in grid
  122.  */
  123. function filter_display_remittance($data)
  124. {
  125.    
  126.     foreach($data["params"] as &$d)
  127.     {
  128.         foreach($d as $k=>$v)
  129.             $d[$k] = strtoupper($d[$k]);
  130.     }
  131. }
  132.  
  133. $out2 = $grid->render("list2");
  134.  
  135.  
  136. ?>
  137. <script>
  138.  
  139. function do_onload(id)
  140.     {
  141.         // remove all tooltip from cell
  142.         $("#list2 td").attr('title','');
  143.         //alert('Simulating, data on load event')        
  144.     }
  145.  
  146. </script>
  147. <?php include_layout_template('header.php'); ?>
  148. <?php include_layout_template('menu.php'); ?>
  149.  
  150. <!-- start page -->
  151. <div id="page">
  152.   <!-- start content -->
  153.  
  154.     <h1 class="pagetitle">&nbsp </h1>
  155.     <div style="margin:10px">
  156.     <?php echo $out2?>
  157.     </div>
  158.  
  159.   <!-- end content -->
  160.  
  161. <?php include_layout_template('footer.php'); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement