1
votes

We are using the jquery fullcalendar v2. I need to set the defaultDate of the MonthView based on the start date of the calendar view.

  1. Show a MonthView Calendar to the User. (October 2014 Month)
  2. Clicking on a date will redirect to a detail page where user can enter the data for that particular date. (detail page)
  3. When user clicks Cancel from the detail page, need to redirect them to the Calendar with the default month of which they were before coming to this detail page. (comeback to October 2014)

For this I can get the start date of the view (i.e. calView.start), which gives 28th Sep, 2014. When I pass this particular value to the defaultView, it shows September as the default Month, but I need to show October 2014 as default.

$('#calendar').fullCalendar({
        theme: true,
        editable: true,
        disableDragging: true,
        disableResizing: true,
        defaultDate: calView.start

This was working fine in the previous version when we set as below:

$('#calendar').fullCalendar({
        theme: true,
        editable: true,
        disableDragging: true,
        disableResizing: true,
        date: calView.start.getDate(),
        month: calView.start.getMonth(),
        year: calView.start.getFullYear(),

Can someone let me know whether we need to handle it differently?

1

1 Answers

2
votes

Edit

The problem is probably that you are getting the first rendered day start and not the first day of the month.

I quote the documentation; "In month-view, this value is often before the 1st day of the month".

Easy fix

Use intervalStart instead.

Another solution

I solved this by getting the date when the user clicks away with

var lastDate = $('#calendar').fullCalendar('getDate');

And then giving it to fullcalendar when I want to render it again:

$('#calendar').fullCalendar({
    defaultDate: lastDate
    ...
});

If your application isn't single page then you would need to save the date in local storage, session storage or something else.