Update the selected dates of date range picker for Twitter Bootstrap

Gustav picture Gustav · Sep 23, 2013 · Viewed 40.8k times · Source

I'm using the date range picker for Twitter Bootstrap, by Dan Grossman.

When initialized, it's possible to set pre-defined values like startDate and endDate. Is it possible to update the values manually later on in a similar way?

What I want to do is to "load" the date range picker with filters I have saved, which includes a start and end date (not by defining pre-defined ranges). Just updating the field of the date range picker through jQuery won't update the actual selection of the calendar.

I guess I should do something like this when initializing the date range picker:

var reportrange = $('#reportrange').daterangepicker(),
DateRangePicker = reportrange.data('daterangepicker');

But then, how to use DateRangePicker to update the date range picker and calendar with new selected dates manually?

Answer

Dan Grossman picture Dan Grossman · Jan 27, 2014

The latest version of this component provides methods for updating the start/end date:

$("#reportrange").data('daterangepicker').setStartDate(startDate);
$("#reportrange").data('daterangepicker').setEndDate(endDate);

You don't have to call the update methods yourself as these will handle all that.