Reputation: 119
I want to remove all events in fullcalendar v5 upon click of a button, the code below works fine
calendar.addEventSource([
{
title: 'Business Lunch',
start: '2020-04-03T01:00:00',
},
]);
But how can I able to remove/clear/delete all events after button click? The older version of fullcalendar has this method
calendar.fullCalendar( 'removeEvents', []);
How about for v5? I tried the code below but it gives me an error remove is not a function
. I even tried calendar.refetchEvents();
but nothing works.
$('.button').click(function(event) {
calendar.remove();
});
Upvotes: 3
Views: 8885
Reputation: 1
@tta & @Leandro Lazzaretti:
Great answers! I was looking for this, and both works, but I found out an important diffenrence between them:
calendar.removeAllEvents(); // This will NOT clear the events source array
and
removeEvents = calendar.getEventSources();
removeEvents.forEach(event => {
event.remove(); // this will clear
});
You can check it out by doing:
removeEvents = calendar.getEventSources();
removeEvents.forEach(event => {
event.remove();
});
calendar.addEventSource('yourSourceHere');
var e = calendar.getEventSources();
console.log(e);
Upvotes: 0
Reputation: 66
Must be called on an Event Source instance. Use getEventSources.
removeEvents = calendar.getEventSources();
removeEvents.forEach(event => {
event.remove();
});
Upvotes: 5