examples.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <!DOCTYPE html>
  2. <html dir="ltr" lang="en-US">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <title>A date range picker for Bootstrap</title>
  6. <link href="http://netdna.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet">
  7. <link href="http://netdna.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet">
  8. <link rel="stylesheet" type="text/css" media="all" href="daterangepicker-bs3.css" />
  9. <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
  10. <script type="text/javascript" src="http://netdna.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
  11. <script type="text/javascript" src="moment.js"></script>
  12. <script type="text/javascript" src="daterangepicker.js"></script>
  13. </head>
  14. <body>
  15. <div class="container">
  16. <div class="span12">
  17. <h1>Usage Examples</h1>
  18. <hr />
  19. <h4>Basic Date Range Picker</h4>
  20. <div class="well">
  21. <form class="form-horizontal">
  22. <fieldset>
  23. <div class="control-group">
  24. <div class="controls">
  25. <div class="input-prepend input-group">
  26. <span class="add-on input-group-addon"><i class="glyphicon glyphicon-calendar fa fa-calendar"></i></span><input type="text" style="width: 200px" name="reservation" id="reservation" class="form-control" value="03/18/2013 - 03/23/2013" />
  27. </div>
  28. </div>
  29. </div>
  30. </fieldset>
  31. </form>
  32. <script type="text/javascript">
  33. $(document).ready(function() {
  34. $('#reservation').daterangepicker(null, function(start, end, label) {
  35. console.log(start.toISOString(), end.toISOString(), label);
  36. });
  37. });
  38. </script>
  39. </div>
  40. <h4>Basic Single Date Picker</h4>
  41. <div class="well">
  42. <form class="form-horizontal">
  43. <fieldset>
  44. <div class="control-group">
  45. <div class="controls">
  46. <div class="input-prepend input-group">
  47. <span class="add-on input-group-addon"><i class="glyphicon glyphicon-calendar fa fa-calendar"></i></span><input type="text" style="width: 200px" name="birthday" id="birthday" class="form-control" value="03/18/2013" />
  48. </div>
  49. </div>
  50. </div>
  51. </fieldset>
  52. </form>
  53. <script type="text/javascript">
  54. $(document).ready(function() {
  55. $('#birthday').daterangepicker({ singleDatePicker: true }, function(start, end, label) {
  56. console.log(start.toISOString(), end.toISOString(), label);
  57. });
  58. });
  59. </script>
  60. </div>
  61. <h4>Date Range &amp; Time Picker with 30 Minute Increments</h4>
  62. <div class="well">
  63. <form class="form-horizontal">
  64. <fieldset>
  65. <div class="control-group">
  66. <label class="control-label" for="reservationtime">Choose your check-in and check-out times:</label>
  67. <div class="controls">
  68. <div class="input-prepend input-group">
  69. <span class="add-on input-group-addon"><i class="glyphicon glyphicon-calendar fa fa-calendar"></i></span>
  70. <input type="text" style="width: 400px" name="reservation" id="reservationtime" class="form-control" value="08/01/2013 1:00 PM - 08/01/2013 1:30 PM" class="span4"/>
  71. </div>
  72. </div>
  73. </div>
  74. </fieldset>
  75. </form>
  76. <script type="text/javascript">
  77. $(document).ready(function() {
  78. $('#reservationtime').daterangepicker({
  79. timePicker: true,
  80. timePickerIncrement: 30,
  81. format: 'MM/DD/YYYY h:mm A'
  82. }, function(start, end, label) {
  83. console.log(start.toISOString(), end.toISOString(), label);
  84. });
  85. });
  86. </script>
  87. </div>
  88. <h4>Options Usage</h4>
  89. <div class="well" style="overflow: auto">
  90. <button id="options1" class="btn btn-primary">Apply Option Set 1</button>
  91. <button id="options2" class="btn btn-primary">Apply Option Set 2</button>
  92. <button id="destroy" class="btn btn-primary">Remove DateRangePicker</button>
  93. <div id="reportrange" class="pull-right" style="background: #fff; cursor: pointer; padding: 5px 10px; border: 1px solid #ccc">
  94. <i class="glyphicon glyphicon-calendar fa fa-calendar"></i>
  95. <span></span> <b class="caret"></b>
  96. </div>
  97. <script type="text/javascript">
  98. $(document).ready(function() {
  99. var cb = function(start, end, label) {
  100. console.log(start.toISOString(), end.toISOString(), label);
  101. $('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
  102. //alert("Callback has fired: [" + start.format('MMMM D, YYYY') + " to " + end.format('MMMM D, YYYY') + ", label = " + label + "]");
  103. };
  104. var optionSet1 = {
  105. startDate: moment().subtract(29, 'days'),
  106. endDate: moment(),
  107. minDate: '01/01/2012',
  108. maxDate: '12/31/2015',
  109. dateLimit: { days: 60 },
  110. showDropdowns: true,
  111. showWeekNumbers: true,
  112. timePicker: false,
  113. timePickerIncrement: 1,
  114. timePicker12Hour: true,
  115. ranges: {
  116. 'Today': [moment(), moment()],
  117. 'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
  118. 'Last 7 Days': [moment().subtract(6, 'days'), moment()],
  119. 'Last 30 Days': [moment().subtract(29, 'days'), moment()],
  120. 'This Month': [moment().startOf('month'), moment().endOf('month')],
  121. 'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
  122. },
  123. opens: 'left',
  124. buttonClasses: ['btn btn-default'],
  125. applyClass: 'btn-sm btn-primary',
  126. cancelClass: 'btn-sm',
  127. format: 'MM/DD/YYYY',
  128. separator: ' to ',
  129. locale: {
  130. applyLabel: 'Submit',
  131. cancelLabel: 'Clear',
  132. fromLabel: 'From',
  133. toLabel: 'To',
  134. customRangeLabel: 'Custom',
  135. daysOfWeek: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr','Sa'],
  136. monthNames: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
  137. firstDay: 1
  138. }
  139. };
  140. var optionSet2 = {
  141. startDate: moment().subtract(7, 'days'),
  142. endDate: moment(),
  143. opens: 'left',
  144. ranges: {
  145. 'Today': [moment(), moment()],
  146. 'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
  147. 'Last 7 Days': [moment().subtract(6, 'days'), moment()],
  148. 'Last 30 Days': [moment().subtract(29, 'days'), moment()],
  149. 'This Month': [moment().startOf('month'), moment().endOf('month')],
  150. 'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
  151. }
  152. };
  153. $('#reportrange span').html(moment().subtract(29, 'days').format('MMMM D, YYYY') + ' - ' + moment().format('MMMM D, YYYY'));
  154. $('#reportrange').daterangepicker(optionSet1, cb);
  155. $('#reportrange').on('show.daterangepicker', function() { console.log("show event fired"); });
  156. $('#reportrange').on('hide.daterangepicker', function() { console.log("hide event fired"); });
  157. $('#reportrange').on('apply.daterangepicker', function(ev, picker) {
  158. console.log("apply event fired, start/end dates are "
  159. + picker.startDate.format('MMMM D, YYYY')
  160. + " to "
  161. + picker.endDate.format('MMMM D, YYYY')
  162. );
  163. });
  164. $('#reportrange').on('cancel.daterangepicker', function(ev, picker) { console.log("cancel event fired"); });
  165. $('#options1').click(function() {
  166. $('#reportrange').data('daterangepicker').setOptions(optionSet1, cb);
  167. });
  168. $('#options2').click(function() {
  169. $('#reportrange').data('daterangepicker').setOptions(optionSet2, cb);
  170. });
  171. $('#destroy').click(function() {
  172. $('#reportrange').data('daterangepicker').remove();
  173. });
  174. });
  175. </script>
  176. </div>
  177. <h4>Plays nicely with Bootstrap dropdowns</h4>
  178. <div class="well">
  179. <div class="dropdown" style="display: inline-block;">
  180. <a data-toggle="dropdown" class="btn btn-primary" href="#">Regular bootstrap dropdown</a>
  181. <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
  182. <li><a href="#">item</a></li>
  183. </ul>
  184. </div>
  185. <div id="reportrange2" class="btn" style="display: inline-block; background: #fff; cursor: pointer; padding: 5px 10px; border: 1px solid #ccc">
  186. <i class="glyphicon glyphicon-calendar fa fa-calendar"></i>
  187. <span></span> <b class="caret"></b>
  188. </div>
  189. <script type="text/javascript">
  190. $(document).ready(function() {
  191. $('#reportrange2 span').html(moment().subtract(29, 'days').format('MMMM D, YYYY') + ' - ' + moment().format('MMMM D, YYYY'));
  192. $('#reportrange2').daterangepicker({
  193. opens: 'center'
  194. });
  195. });
  196. </script>
  197. </div>
  198. <h4>And also can drop "up"</h4>
  199. <div class="well">
  200. <form class="form-horizontal">
  201. <fieldset>
  202. <div class="control-group">
  203. <div class="controls">
  204. <div class="input-prepend input-group">
  205. <span class="add-on input-group-addon"><i class="glyphicon glyphicon-calendar fa fa-calendar"></i></span><input type="text" style="width: 200px" name="dropup" id="dropup" class="form-control" value="03/18/2013 - 03/23/2013" />
  206. </div>
  207. </div>
  208. </div>
  209. </fieldset>
  210. </form>
  211. <script type="text/javascript">
  212. $(document).ready(function() {
  213. $('#dropup').daterangepicker({
  214. drops:'up'
  215. });
  216. });
  217. </script>
  218. </div>
  219. </div>
  220. </div>
  221. </body>
  222. </html>