Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

loading fullcalendar events when the month changes

So I'm a little unsure about how to structure my calendar events with fullcalendar. Currently, when my app loads I'm injecting a json events object into the body of my page, allowing me to init the full calendar quickly, and without an ajax call. On all subsequent month view changes I want to send an ajax request with the given month as an argument so I can pull in that months events. How would I go about doing this? Is this the lazyLoad feature? How can I get the calendar to use the local event data when it initially displays, but then use ajax requests for all subsequent months?

like image 532
Greg Avatar asked Mar 29 '12 16:03

Greg


People also ask

How do I create a dynamic event in Fullcalendar?

although it is not specified on the fullcalender site, it is necessary to assign a value to the "allday" parameter to be able to add new events dynamically. If you set this value to "false", it will not add the event to the AllDay row. If you do "true" it will add to the AllDay row. Save this answer.

How do I change the date on Fullcalendar?

The calendar's dates can change any time the user does the following: click the prev/next buttons, change the view, click a navlink. The dates can also change when the current-date is manipulated via the API, such as when gotoDate is called. datesSet is called after the new date range has been rendered.

How do I get events on Fullcalendar?

Calendar::getEvents Retrieves events that FullCalendar has in memory. This method will return an array of Event Objects that FullCalendar has stored in client-side memory.


3 Answers

Please note in the latest version the viewDisplay has been replaced with viewRender Find how to use it here

I use it like this

        viewRender: function (view, element) {
        }

You can get the start date and end date like this. view.start, view.end

like image 119
Ike Avatar answered Oct 30 '22 15:10

Ike


try to read the docs, events (as a json feed)
other option is refetch/render events every time date has changed viewDisplay

like image 31
zlosim Avatar answered Oct 30 '22 16:10

zlosim


When the json feed (mentioned by zlosim) does not seem to be enough for your ajax, you can either

  • use https://fullcalendar.io/docs/events-function which will be called whenever new data is required. This, however, caches the data internally it seems and the events for one day will not be requested twice. Also, the returned object is not reactive, seems to be cloned.
  • use a plain array for events, but pass a datesRender callback: https://fullcalendar.io/docs/datesRender you can then change your events array appropriately. This is called every time the visible dates change without caching.
like image 1
phil294 Avatar answered Oct 30 '22 15:10

phil294