2

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.

ADyson
  • 57,178
  • 14
  • 51
  • 63
Mike
  • 182
  • 1
  • 3
  • 15

1 Answers1

4

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();
      });
  • I'm an idiot (and new at Javascript!) I was initialising it very similarly to you but creating the calendar var when creating the calendar, so not making it global. I moved it outside and now all is fine. Thanks SO much for the nudge in the right direction. – Mike Sep 16 '20 at 14:09