Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Good way to enable auto refresh of events on the fullCalendar jquery plugin?

Tags:

fullcalendar

Is there a good way to have the fullCalendar jquery plugin auto-refresh its events?

I am able to simply call 'refetchEvents' using a timer, but that presents issues if the user is currently dragging an event (throwing javascript errors during the refresh while the event is dragged). Is there a better way?

like image 533
ericvg Avatar asked Dec 05 '25 15:12

ericvg


1 Answers

Good solution... but is not enough:

var calE = {
        url: 'calendarEvents.do',
        type: 'POST',
        data: {
            siteId: $("#siteId").val()
        },
        error: function() {
            alert('there was an error while fetching events!');
        }
};

function loadCal(){
        $('#calendar').fullCalendar({
                theme: true,
                events: calE,
                editable: false,            
                eventDrop: function(event, delta) {
                        alert(event.title + ' was moved ' + delta + ' days\n' +
                                '(should probably update your database)');
                },          
                loading: function(bool) {
                        if (bool) $('#loading').show();
                        else $('#loading').hide();
                },
                viewDisplay: function(viewObj) {}           
        });

}

function reloadCalendar(){
    $('#calendar').fullCalendar('removeEventSource', calEvent );
    var source = {
            url: 'calendarEvents.do',
            type: 'POST',
            data: {
                siteId: $("#siteId").val()
            },
            error: function() {
                alert('there was an error while fetching events!');
            }
        };
    $('#calendar').fullCalendar('removeEvents');
    $('#calendar').fullCalendar('addEventSource', source );
    $('#calendar').fullCalendar('rerenderEvents');
    calE = source;
}

By using this you'll keep the original algorithm to fetch the data.

like image 90
olman Avatar answered Dec 11 '25 05:12

olman