Reputation: 31
How to get all events id for particular month?
var source = { events: [
{
title : val.xxxxName,
start : val.StartDate,
end : val.EndDate,
xxxxDetailID : val.xxxxDetailID,
}
]};
$('#calendar').fullCalendar( 'addEventSource', source );
I have lots of event for month. I can get all events by using:
$('#calendar').fullCalendar('clientEvents');
But I need only one months event ids.
Upvotes: 2
Views: 1750
Reputation: 2101
You can use your way of getting events in the loading
function of fullCalendar.
Look at this example,
loading: function(){
var allevents = $('#calendar').fullCalendar('clientEvents');
}
Within eventAfterAllRender
callback, get the id
of events for the required month within a loop.
Upvotes: 0
Reputation: 4436
Here is working jsfiddle , click on next and prev buttons .. it will show events in particular month.
.....
....
function getEventsForCurrentMonth(){
for(var i=0; i< events.length; i++) {
if (events[i].start.getMonth() == $('#calendar').fullCalendar('getDate').getMonth()) {
monthEvents.push(events[i].id);
}
}
}
....
Upvotes: 0
Reputation: 617
This should let you pass in any month you want.
Declare an Enum for months.
var Months = { January: 0, February: 1, March: 2, ... };
Pass in your desired month.
var desiredMonth = Months.January;
function getEventsForMonth(desiredMonth) {
var result = new Array();
for(var i = 0; i < source.events.length; i++) {
if(source.events[i].getMonth() == desiredMonth ) {
result.push(source.events[i]);
}
}
return result;
}
$('#calendar').fullCalendar('clientEvents', getEventsForMonth(desiredMonth));
Upvotes: 1
Reputation: 318
When I look at the documentation here I see that you can set a custom filter.
Something like this should work...
$('#calendar').fullCalendar('clientEvents',function(event){
/*Gets the events of the current month in an array*/
if (event.start.getMonth() == $('#calendar').fullCalendar('getDate').getMonth()) {
return true;
}
else {
return false;
};
});
Upvotes: 3