javascriptdaterangepicker

Is there a way to isolate the months in javascript daterangepicker?


I'm implementing a daterangepicker into my application and am wondering how to confine each month to ONLY that month. For example:

I would like this (see the left hand calendar):

enter image description here

But the default is like this

enter image description here

I've reviewed the DateRangePicker Documentation and cannot see a configuration that will do this for me.

My DateRangePicker initilization:

$("#reportrange").daterangepicker
      ranges:
         "Last Week": [moment().subtract("days", moment().day() + 1).subtract("days", 6), moment().subtract("days", moment().day() + 1)]
         "Week to Date": [moment().subtract("days", moment().day()), moment()]
         "Last Month": [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
      startDate: moment().subtract("days", moment().day() + 1).subtract("days", 6)
      endDate: moment().subtract("days", moment().day() + 1),
      alwaysShowCalendars: true
   , (start, end, label) ->
         $("#reportrange span").html start.format("MMMM D, YYYY") + " - " + end.format("MMMM D, YYYY")
         $("[name*='_start_date']").val(start.format("ddd, D MMM YYYY"))
         $("[name*='_end_date']").val(end.format("ddd, D MMM YYYY")).trigger 'change'

My DateRangePicker Frontend with ruby templating

.grid-24.box
   .grid-12
      %h3 Select Date Range
      #reportrange
         %i.glyph-calendar.icon-large
         %span= "#{(DateTime.now - (DateTime.now.wday + 1) - 6).strftime("%B %d, %Y")} - #{(DateTime.now - (DateTime.now.wday + 1)).strftime("%B %d, %Y")} "
         %b.caret
      =hidden_field_tag "charge_start_date", DateTime.now.prev_month.strftime("%a,  %d %b %Y")
      =hidden_field_tag "charge_end_date", DateTime.now.strftime("%a,  %d %b %Y")
.grid-24#display-charges
   =render :partial => "user_charge_data_display", :locals => {users: @users, start_range: (DateTime.now - 30), end_range: DateTime.now}

Solution

  • I went through the documentation and couldn't find the way to do it programmatically, using developers' provided configuration. However, in such situation, you can always go with CSS work-around, by applying visibility: hidden; to the CSS class of the items that are beyond the current month date. Here's what I did:

    .daterangepicker td.off, .daterangepicker td.off.in-range, .daterangepicker td.off.start-date, .daterangepicker td.off.end-date {
      visibility: hidden;
    }
    

    And here's the result:

    enter image description here