dpapatsarouchas
dpapatsarouchas

Reputation: 191

fullcalendar do something when view change

I need to do something when view change. For example when from motnh go to agendaDay.

Didnt work anythink.any ideas?

viewRender:(function() {

                var lastViewName;
                return function(view) {

                    var view = $('#calendar').fullCalendar('getView');
                    alert('The new title of the view is ' + view.title);
                }
            }),

and

viewRender:(function(view) {
                var view = $('#calendar').fullCalendar('getView');
                alert('The new title of the view is ' + view.title);
            }),

Upvotes: 10

Views: 20518

Answers (4)

foxfuzz
foxfuzz

Reputation: 105

As noted by @Willow (thanks), accepted answer will not work in version 5x.

viewRender, eventAfterAllRender, datesRender are all obsolete and break in version 5. Below are some FullCalendar documentations I found listing breaking changes per release.

DatesSet is the property to be used. Screenshot from ver. 5 documentation: enter image description here

Taking your code example, below works for me. In case it benefits someone else.

// version 5.11.0 based code
document.addEventListener('DOMContentLoaded', function() {
  var calendarEl = document.getElementById('calendar');
  var calendar = new FullCalendar.Calendar(calendarEl, {
    ...
    datesSet: function (dateInfo) {
        var view = dateInfo.view;
        alert('The new title of the view is ' + view.title);
    },
    ...
  });

  calendar.render();
});

Upvotes: 6

Willow
Willow

Reputation: 1466

In FullCalendar 5 this seems to be datesSet: https://fullcalendar.io/docs/datesSet

Upvotes: 13

lthomas138
lthomas138

Reputation: 21

Little late but try:

eventAfterAllRender: (function (view) {

// your code

}),

Upvotes: 1

DanielST
DanielST

Reputation: 14133

Small error in the code. You want the function inside the () to return another function but it isn't running. The correct form is:

(function() {
    return function(){...};
})(); //extra parentheses run the function

This is called a Self-Executing Anonymous Function.


Your code works when you do:

viewRender: (function () {
    var lastViewName;
    return function (view) {
        var view = $('#calendar').fullCalendar('getView');
        alert('The new title of the view is ' + view.title);
    }
})(),

Upvotes: 3

Related Questions