Git Product home page Git Product logo

bootstrap-daterangepicker's Introduction

Date Range Picker for Twitter Bootstrap

Improvely.com

This date range picker component for Twitter Bootstrap creates a dropdown menu from which a user can select a range of dates. I created it while building the UI for Improvely, which needed a way to select date ranges for reports.

If invoked with no options, it will present two calendars to choose a start and end date from. Optionally, you can provide a list of date ranges the user can select from instead of choosing dates from the calendars. If attached to a text input, the selected dates will be inserted into the text box. Otherwise, you can provide a custom callback function to receive the selection.

View a demo

Usage

This component relies on Twitter Bootstrap, Moment.js and jQuery.

Separate stylesheets are included for use with Bootstrap 2 or Bootstrap 3.

Basic usage:

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="moment.js"></script>
<script type="text/javascript" src="daterangepicker.js"></script>
<link rel="stylesheet" type="text/css" href="bootstrap.css" />
<link rel="stylesheet" type="text/css" href="daterangepicker-bs3.css" />

<script type="text/javascript">
$(document).ready(function() {
  $('input[name="daterange"]').daterangepicker();
});
</script>

The constructor also takes an optional options object and callback function. The function will be called whenever the selected date range has been changed by the user, and is passed the start and end dates (moment date objects) as parameters.

$('input[name="daterange"]').daterangepicker(
  { 
    format: 'YYYY-MM-DD',
    startDate: '2013-01-01',
    endDate: '2013-12-31'
  },
  function(start, end) {
    alert('A date range was chosen: ' + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD'));
  }
);

Options Reference

startDate: (Date object, moment object or string) The start of the initially selected date range

endDate: (Date object, moment object or string) The end of the initially selected date range

minDate: (Date object, moment object or string) The earliest date a user may select

maxDate: (Date object, moment object or string) The latest date a user may select

dateLimit: (object) The maximum span between the selected start and end dates. Can have any property you can add to a moment object (i.e. days, months)

showDropdowns: (boolean) Show year and month select boxes above calendars to jump to a specific month and year

showWeekNumbers: (boolean) Show week numbers at the start of each week on the calendars

timePicker: (boolean) Allow selection of dates with times, not just dates

timePickerIncrement: (number) Increment of the minutes selection list for times (i.e. 30 to allow only selection of times ending in 0 or 30)

timePicker12Hour: (boolean) Use 12-hour instead of 24-hour times, adding an AM/PM select box

ranges: (object) Set predefined date ranges the user can select from. Each key is the label for the range, and its value an array with two dates representing the bounds of the range

opens: (string: 'left'/'right') Whether the picker appears aligned to the left or to the right of the HTML element it's attached to

buttonClasses: (array) CSS class names that will be added to all buttons in the picker

applyClass: (string) CSS class string that will be added to the apply button

cancelClass: (string) CSS class string that will be added to the cancel button

format: (string) Date/time format string used by moment when parsing or displaying the selected dates

separator: (string) Separator string to display between the start and end date when populating a text input the picker is attached to

locale: (object) Allows you to provide localized strings for buttons and labels, and the first day of week for the calendars

License

This code is made available under the same license as Twitter Bootstrap. Moment.js is included in this repository for convenience. It is available under the MIT license.

--

Copyright 2012-2013 Dan Grossman

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

bootstrap-daterangepicker's People

Contributors

adamstrickland avatar aguilarsoto avatar ansman avatar asm89 avatar chadoh avatar coryjamesfisher avatar dangrossman avatar icdark avatar iterion avatar ivanzgb avatar jennysjogren avatar jmtoball avatar lukencode avatar mgdodge avatar rustybailey avatar thadafinser avatar wcomnisky avatar wojcikstefan avatar

Watchers

 avatar  avatar

Forkers

hmztsc

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.