开发者

Refetch events when switching fullcalendar views

I'm using 3 views in my calendar: month, agendaWeek, and agendaDay. After I add an event, I call refetchEvents to dis开发者_高级运维play the new event. If I add an event from agendaWeek or agendaDay, the refetch will of course grab the events for the week or day. If I then switch to the month view, I only have the events for the week or the day.

I've tried adding a refetchEvents on viewDisplay. The problem with this is that it runs on the initial load which causes the duplication of all the events. Is there a way I can stop refetchEvents from being called during the calendar load?

Is there any other way to force the refetch when switching views?


When creating fullcalendar there is the viewDisplay method which is fired whenever the view is changed. Logically you can use this as a viewChanged event. For example:

$('#calendar').fullCalendar({
    ... 
    viewDisplay: function(view) { alert('viewDisplay(' + view + ')'); }
});

It appears that as of version 1.6.3 the correct callback to use is viewRender

$('#calendar').fullCalendar({
    ...
    viewRender: function(view, element) { alert('new view: ' + view.name); }
});


Sounds like a good idea for an enhancment to fullcalendar library itself - the library could provide callback function for "viewChanged" or even "viewChanging" event. Such thing is really missing, because, if you need to create "AJAX deep linking", you also need to know when the view has changed.

Update: what happens if you change the "lazyFetching" option http://arshaw.com/fullcalendar/docs/event_data/lazyFetching/ of your calendar after you add the event?


Not a perfect idea, but just adding one more alternative...

$('.fc-month-button').click(function () {

});

$('.fc-agendaWeek-button').click(function () {

});


In my case I had to turn off both lazyFetching and events cache:

  eventSources: [
    {
      url: ...,
      cache: false,
    }
  ],
  lazyFetching: false
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜