A date range picker for Twitter Bootstrap
While developing Improvely, having all the components of Twitter Bootstrap at hand pre-styled was a great time saver.
I was in need of a dropdown menu to choose date ranges for reports, and wanted something that would match the existing dropdown and button styles of Bootstrap: thus came about this date range picker component. Download it at GitHub.
For basic use cases like collecting event or reservation dates, you can attach it to a text input to pop up two clickable calendars to choose dates from. For more advanced use cases, you can attach a date range picker to any element, pre-define your own date ranges for the user to choose from, and set a custom callback function to receive the chosen dates.
The date range picker relies on jQuery, Datejs for parsing strings into dates and defining custom ranges, and the Twitter Bootstrap CSS.
Usage:
$('#element').daterangepicker(options, callback);
The examples below show how to use the (optional) options and callback parameters.
Simple Example
<form class="form-horizontal">
<fieldset>
<div class="control-group">
<label class="control-label" for="reservation">Reservation dates:</label>
<div class="controls">
<div class="input-prepend">
<span class="add-on"><i class="icon-calendar"></i></span><input type="text" name="reservation" id="reservation" />
</div>
</div>
</div>
</fieldset>
</form>
<script type="text/javascript">
$(document).ready(function() {
$('#reservation').daterangepicker();
});
</script>
Pre-defined Ranges & Callback Example
<div id="reportrange" class="pull-right">
<i class="icon-calendar icon-large"></i>
<span><?php echo date("F j, Y", strtotime('-30 day')); ?> - <?php echo date("F j, Y"); ?></span> <b class="caret"></b>
</div>
<script type="text/javascript">
$('#reportrange').daterangepicker(
{
ranges: {
'Today': ['today', 'today'],
'Yesterday': ['yesterday', 'yesterday'],
'Last 7 Days': [Date.today().add({ days: -6 }), 'today'],
'Last 30 Days': [Date.today().add({ days: -29 }), 'today'],
'This Month': [Date.today().moveToFirstDayOfMonth(), Date.today().moveToLastDayOfMonth()],
'Last Month': [Date.today().moveToFirstDayOfMonth().add({ months: -1 }), Date.today().moveToFirstDayOfMonth().add({ days: -1 })]
}
},
function(start, end) {
$('#reportrange span').html(start.toString('MMMM d, yyyy') + ' - ' + end.toString('MMMM d, yyyy'));
}
);
</script>
google+
Pingback: ПАРОЧКИ – Подборка полезного для любителей Twitter Bootstrap
Pingback: An Awesome Date Range Picker for Twitter Bootstrap
Pingback: All about Twitter Bootstrap | Jayesh Chandrapal
Pingback: Dan Grossman: выбора диапазона дат для Bootstrap Twitter | my personal Blog
Pingback: Get More web design with Bootstrap. Tools & Tuts Anton Art Network, Jamaica Website Design & Hosting Services, Graphic design and Marketing
Pingback: Useful JavaScript Libraries and jQuery Plugins For Web Developers
Pingback: 扩展Twitter Bootstrap的JavaScript插件 | Chaoyue's Blog