Advertisement
c3media

Issue daterangepicker

Jul 19th, 2018
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.67 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. // include db config
  11. include_once("../../config.php");
  12.  
  13. // include and create object
  14. include(PHPGRID_LIBPATH."inc/jqgrid_dist.php");
  15.  
  16. // Database config file to be passed in phpgrid constructor
  17. $db_conf = array(
  18. "type" => PHPGRID_DBTYPE,
  19. "server" => PHPGRID_DBHOST,
  20. "user" => PHPGRID_DBUSER,
  21. "password" => PHPGRID_DBPASS,
  22. "database" => PHPGRID_DBNAME
  23. );
  24.  
  25. $g = new jqgrid($db_conf);
  26.  
  27. $col = array();
  28. $col["title"] = "Id";
  29. $col["name"] = "id";
  30. $col["width"] = "25";
  31. $cols[] = $col;
  32.  
  33. $col = array();
  34. $col["title"] = "Date";
  35. $col["name"] = "option_id";
  36. $col["width"] = "100";
  37. $col["formatter"] = "date";
  38. $col["editable"] = false; // this column is editable
  39. $col["editoptions"] = array("size"=>40, "defaultValue" => date("Y-m-d"));
  40.  
  41. // date range filter in toolbar
  42. $col["stype"] = "daterange";
  43.  
  44. // Update options for date range picker: http://tamble.github.io/jquery-ui-daterangepicker/#options
  45. $col["searchoptions"]["opts"] = array("initialText"=>"Select date range...");
  46.  
  47. // to set custom ranges
  48. // $col["searchoptions"]["opts"]["presetRanges"] = array( array ("text"=>'Test', "dateStart" => "function() { return moment() }", "dateEnd"=> "function() { return moment().add('weeks', 1).endOf('week'); }" ) );
  49.  
  50. // Update additional datepicker options: http://api.jqueryui.com/datepicker/#options
  51. // $col["searchoptions"]["opts"]["datepickerOptions"] = array("maxDate"=>"-1d", "numberOfMonths"=>2);
  52.  
  53. $col["editrules"] = array("required"=>true, "edithidden"=>true); // and is required
  54. $cols[] = $col;
  55.  
  56.  
  57. $col = array();
  58. $col["title"] = "Product";
  59. $col["name"] = "id";
  60. $col["dbname"] = "p.name"; // this is required as we need to search in name field, not id
  61. $col["width"] = "100";
  62. $col["align"] = "left";
  63. $col["search"] = true;
  64. $col["editable"] = true;
  65. $col["edittype"] = "select"; // render as select
  66. $str = $g->get_dropdown_values("select distinct id as k, name as v from sma_products");
  67. $col["editoptions"] = array("value"=>":;".$str);
  68. $col["formatter"] = "select"; // display label, not value
  69. $cols[] = $col;
  70.  
  71.  
  72. $col = array();
  73. $col["title"] = "SubTotal";
  74. $col["name"] = "subtotal";
  75. $col["width"] = "50";
  76. $col["editable"] = true;
  77. $cols[] = $col;
  78.  
  79. $col = array();
  80. $col["title"] = "Rate";
  81. $col["name"] = "Porcentaje";
  82. $col["width"] = "50";
  83. $col["editable"] = true;
  84. $cols[] = $col;
  85.  
  86.  
  87. $grid["rowNum"] = 10; // by default 20
  88. $grid["sortname"] = 'id'; // by default sort grid by this field
  89. $grid["sortorder"] = "desc"; // ASC or DESC
  90. $grid["caption"] = "Invoice Data"; // caption of grid
  91. $grid["autowidth"] = true; // expand grid to screen width
  92. $grid["multiselect"] = false; // allow you to multi-select through checkboxes
  93. $grid["persistsearch"] = true; // allow you to multi-select through checkboxes
  94. $grid["export"] = array("format"=>"pdf", "filename"=>"my-file", "heading"=>"Invoice Details", "orientation"=>"landscape", "paper"=>"a4");
  95.  
  96. $g->set_options($grid);
  97.  
  98. $g->set_actions(array(
  99. "add"=>false, // allow/disallow add
  100. "edit"=>false, // allow/disallow edit
  101. "delete"=>false, // allow/disallow delete
  102. "rowactions"=>true, // show/hide row wise edit/del/save option
  103. "export"=>true,
  104. "search" => "advance", // show single/multi field search condition (e.g. simple or advance)
  105. "showhidecolumns" => false
  106. )
  107. );
  108.  
  109. // you can provide custom SQL query to display data
  110. $g->select_command = "SELECT r.sale_id, option_id, option_id as option_id2, p.id,
  111. r.subtotal, r.product_id, r.Porcentaje FROM sma_rate r
  112. INNER JOIN sma_products p ON p.id = r.product_id";
  113.  
  114. // this db table will be used for add,edit,delete
  115. $g->table = "sma_rate";
  116.  
  117. // pass the cooked columns to grid
  118. $g->set_columns($cols);
  119.  
  120. // generate grid output, with unique grid name as 'list1'
  121. $out = $g->render("list1");
  122. ?>
  123. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  124. <html>
  125. <head>
  126. <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/themes/redmond/jquery-ui.custom.css"></link>
  127. <link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/jqgrid/css/ui.jqgrid.css"></link>
  128. <script src="../../lib/js/jquery.min.js" type="text/javascript"></script>
  129. <script src="../../lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
  130. <script src="../../lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
  131. <script src="../../lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
  132.  
  133. <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.min.js" type="text/javascript"></script>
  134. <link rel="stylesheet" type="text/css" media="screen" href="https://gitcdn.xyz/repo/tamble/jquery-ui-daterangepicker/0.5.0/jquery.comiseo.daterangepicker.css"></link>
  135. <script src="https://gitcdn.xyz/repo/tamble/jquery-ui-daterangepicker/0.5.0/jquery.comiseo.daterangepicker.js" type="text/javascript"></script>
  136.  
  137. </head>
  138. <body>
  139.  
  140. <div style="margin:10px">
  141. <?php echo $out?>
  142. </div>
  143.  
  144. <script>
  145. // add between operator for search dialog
  146. $.jgrid.search.odata.push({oper:'bt', text:'between'})
  147. </script>
  148.  
  149. <style>
  150. .comiseo-daterangepicker {
  151. z-index: 999;
  152. }
  153. .comiseo-daterangepicker-triggerbutton .ui-button-text
  154. {
  155. padding: 0.1em 2.1em 0.1em 1em;
  156. }
  157. .comiseo-daterangepicker-triggerbutton.ui-button {
  158. background: white none repeat scroll 0 0;
  159. font-weight: normal;
  160. min-width: 100%;
  161. }
  162. .ui-front {
  163. z-index: 951;
  164. }
  165. </style>
  166.  
  167. </body>
  168. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement