FullCalendar v4 navigation button click handler

Viewed 1492

How do I attach a handler to the navigation buttons in FullCalendar v4? There is nothing specified in the official documentation.

enter image description here

2 Answers

One way to get what you need is to hide the default prev and next buttons and replace with your own custom buttons, for which there are click callbacks.

Please see https://codepen.io/ormasoftchile/pen/NVJeez for a working example.

    customButtons: {
      customprev: {
        text: '<',
        click: function() {
          alert('clicked custom button 1!');
          calendar.prev();
        }
      },
      customnext: {
        text: '>',
        click: function() {
          alert('clicked custom button 2!');
          calendar.next();
        }
      }
    }

Regards, Cristian

The only build-in method is the events: fn () callback. From the docs

FullCalendar will call this function whenever it needs new event data. This is triggered when the user clicks prev/next or switches views.

document.addEventListener('DOMContentLoaded', function() {
    var calendarEl = document.getElementById('calendar');

    var calendar = new FullCalendar.Calendar(calendarEl, {
        plugins: [ 'dayGrid' ],
        defaultView: 'dayGridMonth',
        events: function (info) {
            console.log(info);
        }
    });

    calendar.render();
});
Related