BaconJuice
BaconJuice

Reputation: 3779

How to remove events on fullCalendar based on className

I was wondering if it was possible to remove events and render the fullcalendar again based on a className.

I have something that looks like this for now and it doesn't seem to work as planned.

if(bla = bla){
  displayCalData(myJsonData);   
 }

function displayCalData(json){
    //Define the cal ID to feed data too.
    var calendar = $('#calendar');
    calendar.fullCalendar('removeEvents',myRemove);
    $.each(json, function(i, item) {
        //Create block render
        var displayText = item.displayName;

        var eventObject = {
                title: displayText,
                start: item.startDate,
                end : item.endDate,
                allDay:true,
                color: '#BABBBF',
                editable : false,
                className : "user_block"
        };   
        calendar.fullCalendar('renderEvent', eventObject, true);
    }); 
}
function myRemove(event) {
    return "user_block" === event.className; // ensure your events have this custom class !
}

Also something to keep in mind, onLoad fullCalendar is also loaded with other event data from a seperate call.

Is there a way that I can remove all events on the calendar with the className "user_block" and re-render the calendar with the new data?

Thank you for reading and your help.

Upvotes: 0

Views: 3411

Answers (1)

BaconJuice
BaconJuice

Reputation: 3779

Adding the function directly to removeEvents seem to do the trick

calendar.fullCalendar('removeEvents', function(event) {
    return event.className == "user_block";
});

Upvotes: 3

Related Questions