1

I'm using the date picker to allow a user to select start and end dates. When the page first loads, both date pickers will display the current month the first time the calendar is opened.

However, I want the start datepicker to open up a view from one year in the past.

I've looked through the api (options and methods) and haven't found anything to specify a month.

Has anybody tried this?

Smeegs
  • 9,151
  • 5
  • 42
  • 78

2 Answers2

3

I don't quite get what view means. Just shooting in the dark - if you want to limit the start to 1 year in the past or on certain month in the past, there is a configuration option min.

From the Kendo examples:

<input id="datepicker" />
<script>
$("#datepicker").kendoDatePicker({
    min: new Date(2011, 0, 1) // sets min date to Jan 1st, 2011
});
</script>

Update:

var datepicker = $("#datepicker").data("kendoDatePicker");
var d = new Date ();
$("#datepicker").kendoDatePicker({                    
   value: new Date (d.setFullYear(d.getFullYear() - 1))
});

So this should open the "view" at this day 1 year ago. Live at the Dojo

Bakudan
  • 19,134
  • 9
  • 53
  • 73
  • View is what appears when you open the calendar. By default when you click the calendar icon. It opens with the current month in view. I want it to open one year in the past. – Smeegs Jun 27 '16 at 20:07
  • Thanks for the help, but this isn't really what I'm looking for. The dojo you links throws a JS error and the calendar icon needs to be clicked twice to show the popup. The other issue that you're setting the value. Which I don't want to do. – Smeegs Jun 27 '16 at 23:17
2

There is a property called dateView that can have the value set.

Dojo Demo

  var datepicker = $("#datepicker").data("kendoDatePicker");
  datepicker.bind('open', function() {
     if (this.value() !== this.dateView.value()) {
       this.dateView.value(null);
     }
  });
  datepicker.dateView.value(dt);

This will update the value in the popup calendar without updating the value of the widget itself.

Edit: This actually causes a bug where clicking the selected dateView value doesn't update the actual picker value. I've added a handler for the open event to take care of the mismatch and clear the selected dateView value.

Smeegs
  • 9,151
  • 5
  • 42
  • 78