vuetifyjs / vuetify

🐉 Vue Component Framework
https://vuetifyjs.com
MIT License
39.67k stars 6.95k forks source link

[Feature Request] Date Range Picker #1646

Closed wernerm closed 4 years ago

wernerm commented 7 years ago

A component that facilitates the selection of a pair of dates, which can be implemented as generic start and end dates.

What will it allow you to do that you can't do today?

The current v-date-picker only allows for selection of a single date at a time. A date range picker will facilitate the selection of a pair of dates.

How will it make current work-arounds straightforward?

Currently two separate v-date-pickers will have to be used with code to facilitate synchronising their dates. Here's an example of a crude workaround utilising v-date-picker that I have implemented for a recent project:

screenshot_20170909_174819

Inspiration

Element UI's datepicker's functionality serves as inspiration:

screenshot_20170909_173006

Specific features requested:

bdeo commented 6 years ago

Is there a target release for this?

paladin2005 commented 6 years ago

@wernerm can you share your custom-date-range html template?

OtavioCostaLima commented 6 years ago

apoio

donPuerto commented 6 years ago

This is also from google data studio image

image

image

EvanZ commented 6 years ago

Came here for this too. Was just looking at Google Analytics design.

screen shot 2017-12-06 at 7 45 26 am
ghost commented 6 years ago

Supporting this request, it's an important part of most people's UI and using two date pickers is often a bit unnatural.

jmauerhan commented 6 years ago

I'd like this for time ranges as well!

praveenpuglia commented 6 years ago

This may seem like promoting it but till the time a fully built one comes in vuetify, I made up my own solution. It's not perfect but it does the job.

Feel free to help it make better. :)

https://github.com/praveenpuglia/vuetify-daterange-picker

renztoygwapo commented 6 years ago

any updates for the date picker range request?

maxcook commented 6 years ago

This is such an important feature for many apps. +1

samirph commented 6 years ago

On every Vuetify version update I wonder if date range/period support was added +1

wernerm commented 6 years ago

If you would like to show support for this requested feature, please add a thumbs-up reaction to the original feature request above. (All "+1" comments will be deleted.)

vincebanzon commented 6 years ago

I hope they're working on it by now.

NikoNagy commented 6 years ago

Any update on this ?

Can we hope to see this in Front-End Pack ? 🤞

Thanks for your work.

mariokresic commented 6 years ago

Hello everyone, temporary this function can be achieved with the events functionality. Events array should contain all dates from DateStart to DateEnd and custom-class for event-color. Custom class must be modified so it highlights selected dates-range.

I hope this will help someone.

Edit: here is quick example. screenshot from 2018-07-25 19-38-03

praveenpuglia commented 6 years ago

@mariokresic I have been thinking of doing this in https://github.com/praveenpuglia/vuetify-daterange-picker but afraid of when that might break so didn't do it. Would you like to send a PR and add that functionality there? That would be great :)

mariokresic commented 6 years ago

@praveenpuglia I will try to do it this weekend :)

praveenpuglia commented 6 years ago

Hi @mariokresic ! did you get a chance to see if you can do something for the component i mentioned? Probably shouldn't be talking here just to you. Let's meet somewhere else? praveenpuglia AT gmail.com ?

acidjazz commented 6 years ago

@mariokresic how about sharing the code used for that image as well?

mariokresic commented 6 years ago

@acidjazz here you go https://github.com/praveenpuglia/vuetify-daterange-picker/pull/26

I'll also try to create pull request for this feature in vuetify/vuetify

Fohlen commented 5 years ago

My current workaround for this feature is as follows:

<template>
  <div>
   <v-date-picker
     v-model="dates"
     :multiple="true"
     :min="min"
     :max=""
    />
  </div>
</template>

import addMonths from 'date-fns/add_months'
import subMonths from 'date-fns/sub_months'
import subDays from 'date-fns/sub_days'

<script>
export default {
  data () {
    return {
      dates: []
    }
  },
  computed: {
    min () {
      let min
      if (this.dates.length < 1) {
        min = subMonths(new Date(), 6)
      } else {
        min = subDays(new Date(this.dates[0]), 1)
      }
      return min.toISOString()
    },
    max () {
      let max
      if (this.dates.length <= 1) {
        max = addMonths(new Date(), 6)
      } else if (this.dates.length > 1) {
        max = new Date(this.dates[1])
      } else {
        max = addMonths(this.dates[0], 6)
      }
      return max.toISOString()
    },
    dateRange () {
      let sortedDates = this.dates.sort((a, b) => {
        if (a > b) {
          return 1
        } else if (a < b) {
         return -1
        } else {
         return 0
        }
      })

      return {
        start: sortedDays[0],
        end: sortedDays[sortedDays.length - 1]
      } 
    }
  }
}

The way this "hack" works is:

If you want to use this then you will probably need to substitute date-fns by something you fancy. One can probably also enhance this by making :events all dates between start and end, so it appears to be marked. Only downside: you can select more than two dates, which is confusing to the user. However I consider that more of a edge case because the majority of users (especially mobile) will never try this. Hope it helps somebody!

ngloom commented 5 years ago

Date range picker is a key component for time span related system (like dashboard) still looking forward for your official support. Ps, thanks for the great work !

danchapuk commented 5 years ago

Anyone know of a good fix for this yet? Standard stuff really for dashboards and booking apps. Thanks in advance :)

curiousPup commented 5 years ago

Any updates on this?

ngloom commented 5 years ago

Hi, guys, After working with vuetify for a while, I begin to like Vuetify. But sadly Date Range Picker is a very important component for our system, i didn't find any good enough solution by now.

So i just find one ugly but works Way, by Using ElementUI Date Picker, hope to provide a solution for those need it .

just add this in plugins/vuetify.js

import { DatePicker } from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import lang from 'element-ui/lib/locale/lang/en'
import locale from 'element-ui/lib/locale'

// configure language
locale.use(lang)

Vue.component(DatePicker.name, DatePicker);

Vue.use( Vuetify, { ...

and you can using date picker range in system

<el-date-picker v-model='range' type="daterange"/>

and the final result is as below .

qq20190109-115941-hd

At the end ,

  1. Element UI is not designed for mobile usage, so it might work well there;
  2. The temporary solution is ugly, and still waiting for the official version;
  3. Really appreciate for the great work, thanks guys.
maarten-postmastery commented 5 years ago

Vuetify is the most comprehensive modern open source UI Controls library I found. But the omission of a date range picker is quite annoying, and also suprising. It's commonly used in reporting applications.

Besides Element UI, Syncfusion includes a date range picker in its ESJ 2 toolkit for Vue. It supports:

syncfusion-daterange-picker

effysetumeni commented 5 years ago

any updates on the date picker ? @johnleider

Darkside73 commented 5 years ago

Check out my dead simple implementation of date range picker https://gist.github.com/Darkside73/24b6bf95c984ba616b0d71f144042f16 1549571110332

mgohin commented 5 years ago

Perfect solution @Darkside73 👍

nevendyulgerov commented 5 years ago

Here's my solution to this problem. A combo between vuetify and vue-flatpickr-component. I am using a v-text-field on top of the default flatpickr input field to maintain UI consistency with vuetify:

<template>
  <div data-component="date-picker">
    <v-text-field
      v-model="date"
      type="text"
      label="Select date range"
      class="date-time-field"
      prepend-inner-icon="date_range"
      :background-color="colors.shades.white"
      box
      @focus="toggleDatePicker"
    />

    <flat-pickr
      ref="datePicker"
      v-model="dateText"
      :placeholder="placeholder"
      :config="dateConfig"
    />
  </div>
</template>

<script>
  import colors from 'vuetify/es5/util/colors';
  import flatPickr from 'vue-flatpickr-component';
  import 'flatpickr/dist/flatpickr.css';

  export default {
    components: {
      flatPickr
    },
    props: {
      date: {
        type: String,
        required: true
      },
      placeholder: {
        type: String,
        default: ''
      },
      config: {
        type: Object,
        required: true
      },
      onChange: {
        type: Function,
        required: true
      }
    },
    data() {
      return {
        dateText: '',
        dateConfig: {},
        isOn: false,
        colors
      };
    },
    watch: {
      dateText(nextDate) {
        this.onChange(nextDate);
      }
    },
    created() {
      this.dateConfig = {
        ...this.config,
        onOpen: () => {
          this.isOn = true;
        },
        onClose: () => {
          this.isOn = false;
        }
      };
    },
    methods: {
      toggleDatePicker() {
        this.isOn = !this.isOn;

        if (this.isOn) {
          this.openDatePicker();
        } else {
          this.closeDatePicker();
        }
      },
      getDatePickerInstance() {
        return this.$refs.datePicker.$vnode.elm._flatpickr;
      },
      openDatePicker() {
        const datePicker = this.getDatePickerInstance();
        datePicker.open();
      },
      closeDatePicker() {
        const datePicker = this.getDatePickerInstance();
        datePicker.close();
      }
    }
  };
</script>

<style lang="stylus" scoped>
  [data-component="date-picker"] {
    position: relative;

    .date-time-field {
      z-index: 10;
    }

    .flatpickr-input {
      position: absolute;
      top: 0;
      left: 0;
    }
  }
</style>
a-di-ez commented 5 years ago

My version of @Darkside73 idea: https://gist.github.com/a-di-ez/e89d381e95e9745b2a88854f148137bb image

jonnylink commented 5 years ago

Is this on the roadmap at all? Just wondering if I should check back or move on.

nekosaur commented 5 years ago

It is. Hopefully makes it in to 2.0, but no guarantees

peluprvi commented 5 years ago

Another design approach by https://github.com/leavjenn/SmoothDateRangePicker

date_range_picker

johnleider commented 5 years ago

We haven't forgotten about this. It's understood that this is a highly requested feature and it is something we definitely intend to implement. Most of our resources have been allocated towards the v2.0 release, which is a herculean task and detracts from getting to some features. We thank you for understanding and your patience.

If you would like to collaborate on adding this feature to our existing date-picker, please message me in the discord community.

alvinthen commented 5 years ago

A collab with https://vcalendar.io/ would be great

ngloom commented 5 years ago

Vuetify 2.0 is released today and still no date range picker T.T

Tinoooo commented 5 years ago

@ngloom The date range picker was not planned for Vuetify 2.0

YipingRuan commented 5 years ago

VDatePicker

esynaps commented 5 years ago

It would be great to have time pickers too ie a DateTimeRangePicker

th3n3wguy commented 4 years ago

I just need to jump in here and give an absolutely MASSIVE :+1: to the work by @YipingRuan. I am using this feature in my application now and it is amazingly simple.

chans-me commented 4 years ago

I've added date range highlighter in this codepen https://codepen.io/chansv/pen/OJVWBbG?editors=0010

NaturalDevCR commented 3 years ago

Hopefully this is not forgotten, absolutely a great feature to add

YipingRuan commented 3 years ago

Hopefully this is not forgotten, absolutely a great feature to add

https://v2.vuetifyjs.com/en/components/date-pickers/#date-pickers-range

buzzy commented 3 years ago

Why does it say "2 selected" when you select a range? Makes absolutely no sense. Why would it not reflect the number of days that are between the dates? Writing "2 selected" when the user clearly sees that X number of days are selected is very confusing. I understand that the underlying array has 2 dates, but that is not what should be shown to the end user.

jacekkarczmarczyk commented 3 years ago

https://github.com/vuetifyjs/vuetify/issues/9586

We kindly ask users to not comment on closed/resolved issues. If you believe that this issue has not been correctly resolved, please create a new issue showing the regression or reach out to us in our Discord community.

Thank you for your contribution and interest in improving Vuetify.