Search code examples
jquerydaterangepickerbootstrap-daterangepicker

How to extend custom date range selection in bootstrape daterangepicker


I am using bootstrap daterangepicker plugin, I am facing problem by selecting large range like 3-4 years in custom range. currently it allows custom range within one month only. I tried the minDate and maxDate from other plugin which is also not working here.

And how can I search all time data by clicking all time tab and search it within minDate and maxDate range.

jsFiddle

 $('.selectrange').daterangepicker({
    showDropdowns: true,
    timePicker: true,
    minDate: [moment().subtract(20,'years'),'inclusive'],
    maxDate: [moment(),'inclusive'],
    ranges: {
       'Today': [moment(), moment()],
       'Last 7 Days': [moment().subtract(6, 'days'), moment()],
       'Last 30 Days': [moment().subtract(29, 'days'), moment()],
       'This Month': [moment().startOf('month'), moment().endOf('month')],
       'All Time':'all-time', // [minDate, maxDate]
    }
});

Solution

  • I think this should do the trick for you:

    Add option linkedCalendars: false, for example:

    Code:

    $('.selectrange').daterangepicker({
        linkedCalendars: false,
        showDropdowns: true,
        timePicker: true,
        minDate: moment().subtract(20, 'years'),
        maxDate: moment(),
        ranges: {
            'Today': [moment(), moment()],
            'Last 7 Days': [moment().subtract(6, 'days'), moment()],
            'Last 30 Days': [moment().subtract(29, 'days'), moment()],
            'This Month': [moment().startOf('month'), moment().endOf('month')],
            'All Time': 'all-time', // [minDate, maxDate]
        }
    });
    

    Screenshot:

    Date Range Picker