Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set full calendar to a specific start date when it's initialized for the 1st time?

I would like to set the initial month to an arbitrary month when I call the function to display the calendar.

Say for example the user selects a date last june (June 2011) somewhere else and I want fullcalendar to show up with a month display of April before (April 2010). And yes, this is just to make a case, not to make sense ;-) )

I tried to call 'gotodate' before I then subsequently call the display function but this doesn't seem to work

$('#calendar').fullCalendar( 'gotoDate', currentdate); $('#calendar').fullCalendar({     header: {left: 'prevYear,prev,today,next,nextYear',          center: 'title', right: 'month,basicWeek,basicDay' etc...} 

Could someone eventually please provide an example how to do this properly?

like image 281
Stefan Avatar asked Nov 17 '11 21:11

Stefan


People also ask

How do I turn off past dates in Fullcalendar?

You can try the following thread's solution(dayClick or select function to disable the dayclick for the past dates in fullcalendar). You can visit the fullcalendar support center and post your fullcalendar question on the StackOverflow fullcalendar tag.


2 Answers

You should use the options 'year', 'month', and 'date' when initializing to specify the initial date value used by fullcalendar:

$('#calendar').fullCalendar({  year: 2012,  month: 4,  date: 25 });  // This will initialize for May 25th, 2012. 

See the function setYMD(date,y,m,d) in the fullcalendar.js file; note that the JavaScript setMonth, setDate, and setFullYear functions are used, so your month value needs to be 0-based (Jan is 0).

UPDATE: As others have noted in the comments, the correct way now (V3 as of writing this edit) is to initialize the defaultDate property to a value that is

anything the Moment constructor accepts, including an ISO8601 date string like "2014-02-01"

as it uses Moment.js. Documentation here.

Updated example:

$('#calendar').fullCalendar({     defaultDate: "2012-05-25" });  // This will initialize for May 25th, 2012. 
like image 200
Jammerms Avatar answered Sep 21 '22 10:09

Jammerms


You have it backwards. Display the calendar first, and then call gotoDate.

$('#calendar').fullCalendar({   // Options });  $('#calendar').fullCalendar('gotoDate', currentDate); 
like image 35
Brandon Avatar answered Sep 22 '22 10:09

Brandon