Removing specific events using removeEvents

I just started using this plugin and I had problems deleting the events that I just created. I can delete all events when using eventClick, but not specific in eventClick.

Any help would be greatly appreciated. Here is my code.

<script type='text/javascript'> $(document).ready(function() { var date = new Date(); var d = date.getDate(); var m = date.getMonth(); var y = date.getFullYear(); var calendar = $('#calendar').fullCalendar({ header: { left: 'prev,next today', center: 'title', right: 'month,agendaWeek,agendaDay' }, selectable: true, selectHelper: true, select: function(start, end, allDay) { var title = prompt('Trade Show Name:'); if (title) { calendar.fullCalendar('renderEvent', { title: title, start: start, end: end, allDay: allDay, id: 12 }, true // make the event "stick" ); $('input[name="startDate"]').val(start); } calendar.fullCalendar('unselect'); }, eventClick: function(calEvent, jsEvent, view) { $('#calendar').fullCalendar('removeEvents', function (calEvent) { return true; });, editable: true }); }); 
+7
source share
1 answer

You can do this in two ways:

1) Set a unique identifier for each of your events and pass these identifiers to the removeEvents call.

 eventClick: function (calEvent, jsEvent, view) { $('#calendar').fullCalendar('removeEvents', calEvent._id); } 

Here _id is the unique fullCalendar identifier.

2) Pass the filter function to delete the desired event.

Given that you are trying to do this in eventClick , I suggest you use the second one. An example of your case is as follows:

 eventClick: function (calEvent, jsEvent, view) { $('#calendar').fullCalendar('removeEvents', function (calEvent) { return true; }); } 

Here, the filter function passed to removeEvents accepts the event you want to remove and returns true. Since you are doing this in eventClick , all you have to do is pass calEvent .

Hope this helps!

+24
source

All Articles