Ted Scheckler
Ted Scheckler

Reputation: 1511

FullCalendar javascript - refetchEvents not updating calendar

When I update the 'events' object with a new event and call calander.fullCalendar('refetchEvents') the calendar is not refreshed.

Example:

events = [ { title  : 'event1', start  : '2015-11-01' } ];
calendar = jQuery("#calendar").fullCalendar({ events: events });
events = [ { title  : 'event2', start  : '2015-11-02' } ];
console.log(events);
calendar.fullCalendar('refetchEvents');

Still only shows 'event1' even though I expect 'event2' to show up.

http://jsfiddle.net/u1fjfbzw/

Upvotes: 1

Views: 17489

Answers (1)

smcd
smcd

Reputation: 3265

A simplistic way to get event1 and event2 to both show up is add events array again as an event source. http://jsfiddle.net/u1fjfbzw/1/

events = [ { title  : 'event1', start  : '2015-11-01' } ];
calendar = jQuery("#calendar").fullCalendar({ events: events });
events = [ { title  : 'event2', start  : '2015-11-02' } ];

/* This will make it show up */
calendar.fullCalendar('addEventSource', events);

calendar.fullCalendar('refetchEvents');

The 'events' array in your code is separate from fullCalendar's internal events. From fullcalendar.js 2.4.0:

else if (typeof sourceInput === 'object') {
    source = $.extend({}, sourceInput); // shallow copy
}

Upvotes: 4

Related Questions