Javascript FullCalendar refetchEvents V5 after modal close

Viewed 2372

I'm converting a V4 fullcalendar to V5 and the code I used to refetch the events after the modal closes no longer works. The code was

$('#fullCalModal').on('hidden.bs.modal', function () {
    $('#calendar').fullCalendar( 'refetchEvents' );
});

The documentation just say this

calendar.refetchEvents()

But it has no reference to calendar, it just says "calendar.refetchEvents is not a function"

I've been googling and trying things all afternoon with no luck, so any help much appreciated.

1 Answers

The FullCalendar V5 changed the initialization completely, so you need to implement v5 like below-

var calendar;
      $(document).ready(function () {
        // new way to init full calendar in v5
        var calendarEl = document.getElementById('calendar');
        // store calendar reference in global variable like below so you can use it later.
        calendar = new FullCalendar.Calendar(calendarEl, {
          initialView: 'dayGridMonth'
        });
        calendar.render();
      });
      // so your code will be
      $('#fullCalModal').on('hidden.bs.modal', function () {
        calendar.refetchEvents();
      });
Related