I have two types of events in my fullCalendar. Few are the fetched from the eventSources using :
$('calendar').fullCalendar('addEventSource' , 'source')
And few are created by the user. I am using
$('calendar').fullCalendar('renderEvent', eventData, true)
Now upon clicking a button I want to remove all the events that are obtained from the eventSources and retain those that are created by the user.
I tried doing :
$('calendar').fullCalendar('removeEventSource' , function(e){ return true ; } ) ;
But that doesn't work. How do I achieve doing the job ?
You can simply call:
$('#calendar').fullCalendar('removeEventSources');
I did exactly what you want to do in a recent project. Fullcalendar supports nonstandard fields.
Non-standard Fields
In addition to the fields above, you may also include your own non-standard fields in each Event Object. FullCalendar will not modify or delete these fields. For example, developers often include a description field for use in callbacks such as eventRender.
Source
So you could do something like
//Save user created event
$('#calendar').fullCalendar('renderEvent', {
title: title,
end: end,
start: start,
editable : true,
//nonstandard field
isUserCreated: true,
description: description,
});
then to remove events that hasn't been created by user
//Get all client events
var allEvents = $('#calendar').fullCalendar('clientEvents');
var userEventIds= [];
//Find ever non usercreated event and push the id to an array
$.each(allEvents,function(index, value){
if(value.isUserCreated !== true){
userEventIds.push(value._id);
}
});
//Remove events with ids of non usercreated events
$('#calendar').fullCalendar( 'removeEvents', userEventIds);
or if you need less control then simply (as @A1rPun suggested)
$('#calendar').fullCalendar( 'removeEvents', function(e){ return !e.isUserCreated});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With