In jQuery fullcalendar we have previous and next buttons. How can we call some events on click of these buttons?
When the next and previous buttons are clicked, the events function is called. Here is an example to load data for the current year:
$(document).ready(function() {
loadCal();
});
function loadCal() {
var current_url = '';
var new_url = '';
$('#calendar').fullCalendar({
// other options here...
events: function(start, end, callback) {
var year = end.getFullYear();
new_url = '/api/user/events/list/' + id + '/year/' + year;
if (new_url != current_url) {
$.ajax({
url: new_url,
dataType: 'json',
type: 'POST',
success: function(response) {
current_url = new_url;
user_events = response;
callback(response);
}
})
} else {
callback(user_events);
}
}
})
}
When you retrieve the results in a query, make sure you include at least the last 10 days from the previous year and the first 10 days from the next year.