Jim Patterson
Jim Patterson

Reputation: 307

FullCalendar - extract displayed events

Is it possible to discover/extract the currently displayed events from the FullCalendar object, (ref: http://arshaw.com/fullcalendar)?

Ideally, I'd like a secondary display for events, alongside the calendar, which should show only the currently displayed events, (e.g. if the calendar is on "March 2012", I only want to see March 2012 events in the secondary list).

I'm guessing I'll nedd to construct some sort of filter, but was hoping I might be able to pull the details straight back off the calendar. I figure the plugin must already have established which are valid for display...

Any pointers to a function/property I've missed would be greatly appreciated.

Upvotes: 4

Views: 5200

Answers (3)

ptica
ptica

Reputation: 747

with version 2.x you can filter all client events loaded so far by the current view's intervalStart & intervalEnd - I use a factory function getIdOrFilter to do so

App.getIdOrFilter = function () {
    var view = $('#calendar').fullCalendar('getView');
    var start = view.intervalStart;
    var end   = view.intervalEnd;
    return function (e) {
        // this is our event filter
        if (e.start >= start && e.end <= end) {
            // event e is within the view interval
            return true;
        }
        // event e is not within the current displayed interval
        return false;
    };
}

...

var events = $('#calendar').fullCalendar('clientEvents', App.getIdOrFilter());

Upvotes: 6

Stephen Reid
Stephen Reid

Reputation: 701

Thanks to James Ellis-Jones, I implemented this on a fork of the Full Calendar resourceviews and sent a pull request to the Full Calendar resourceViews owner.

https://github.com/stephenreid/fullcalendar/commit/808a0ac2ff8e9f900af263049cc95a7d4e2b6546

Upvotes: 0

James Ellis-Jones
James Ellis-Jones

Reputation: 3092

Yes this is surprisingly hard to do. I've been digging around in FullCalendar a lot recently as I've been hacking a load of extra functionality into it for my own purposes. It doesn't store the information internally in that form but you can get at it with a small hack:

Insert at line 4243 (in fullcalendar 1.5.2)

t.eventResize = eventResize
//add starts
t.getShownEvents = function () {
  evs = [];
  for (id in eventElementsByID)
    evs = evs.concat(eventsByID[id]);
  return evs;
}
//add ends

Then do this to get an array of event objects currently being displayed:

var evs = $('#calendar').fullCalendar('getView').getShownEvents();

Upvotes: 2

Related Questions