Reputation: 326
How do I add an event after all events have been removed? What I trying to do is set it up so that when you click on the jQuery Datepicker, it removes all events, and adds only from the selected month.
Here is my code:
$(".datepicker").datepicker({
changeMonth: true,
changeYear: true,
onSelect: function(dateText, inst) {
var date = new Date(dateText);
calendar
.fullCalendar('gotoDate', date.getFullYear(), date.getMonth(), date.getDate())
.fullCalendar('changeView','agendaDay')
.fullCalendar('removeEvents');
Events.getEvents({
year: date.getFullYear(),
month: date.getMonth() + 1
},function(events) {
$(events).each(function(index,event) {
console.log(event)
calendar.fullCalendar('renderEvent',event,true);
});
});
}
});
If I call fullCalendar('removeEvents'), everything works great except that duplicate events, but if I add removeEvents, it removes all events, but does not add the other...
What am I doing wrong?
Upvotes: 1
Views: 882
Reputation: 326
I figure out.
Only need to
change calendar.fullCalendar('renderEvent',event,true);
into
calendar.fullCalendar('addEventSource',events);
Note that, you can not add 1 event, you need to add all in one time. In my example events is array where holding all events.
Upvotes: 1