Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listener for "date change" in FullCalendar?

Is there any way to attach a listener to FullCalendar that will be fired whenever the currently viewed date is changed, i.e. if you are in Month view, going to the next month would fire the event passing the Date for the first day of the month, and the same for changing weeks in Week view, day in Day view etc.

The only exposed listener that would be close to this is the dayClick callback, but that's no good because it only fires when a user clicks in an actual day's cell, not for example when the Next/prev/today controls are pressed in the header bar.

I want this functionality to be able to sync the currently viewed month in FullCalendar with a ExtJS datepicker component, so if the viewed month is changed in FullCalendar, then the Datepicker is updated to show that same month. (think Google Calendar's UI with its "mini calendar" in the top left being the datepicker).

like image 845
Bill Dami Avatar asked Jun 20 '11 13:06

Bill Dami


People also ask

How do I change the date on fullCalendar?

The calendar's dates can change any time the user does the following: click the prev/next buttons, change the view, click a navlink. The dates can also change when the current-date is manipulated via the API, such as when gotoDate is called. datesSet is called after the new date range has been rendered.

How do I start and end date in fullCalendar?

We can get start date by getView event with intervalStart. We can get end date by getView event with intervalEnd. var month = $('#calendar'). fullCalendar('getView').


2 Answers

Bill,

I know this question is pretty much ancient, but I needed a solution and figured I'd post it here for others. I solved the problem myself by attaching the viewDisplay event to my calendar (this event was removed in v2 of FullCalendar, viewRender may be used instead).

$("#calendar").fullCalendar({     viewDisplay: function (element) {      } }); 

Once you have access to the element parameter, you can get the date by using element.start or element.visStart. If you're in the month view, start will provide you with the first day of the month that you're viewing, visStart will give you the first visible day of the month

like image 157
Anthony Shaw Avatar answered Oct 01 '22 10:10

Anthony Shaw


This is how I did it:

$("#calendar").fullCalendar({  viewRender: function(view, element){         var currentdate = view.intervalStart;         $('#datepicker').datepicker().datepicker('setDate', new Date(currentdate));     }      }); 

In month view, intervalStart will return the first day of the month being displayed on the FullCalendar, rather than the first visible day, which is usually a day near the end of the previous month.

like image 24
user3241874 Avatar answered Oct 01 '22 09:10

user3241874