In this post, we will learn how to change a calendar's view so that when we click the MonthView date, it redirects to the WeekView and goes back to the MonthView when clicked again. Here is a simple jQuery code for doing this action.
Write the below code in dayClick for changing the view of the calendar.
- dayClick: function(date, jsEvent, view) {
- $('#calendar').fullCalendar('gotoDate',date);
- $('#calendar').fullCalendar('changeView','agendaWeek');
- },
Write the below code in eventClick for changing the view of the calendar.
- eventClick: function(calEvent, event, jsEvent) {
- var dt = calEvent.start;
- $('#calendar').fullCalendar('gotoDate',dt);
- $('#calendar').fullCalendar('changeView','agendaWeek');
- }
Below is the sample code for checking the View name. Add this code to the above event code and you will get the View name.
- var view = $('#calendar').fullCalendar('getView');
-
- alert(view.name == 'month');
- {
- $('#calendar').fullCalendar('gotoDate', date);
- $('#calendar').fullCalendar('changeView', 'agendaWeek');
- }