Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fullcalendar add events dynamically

I'm trying to create events in my full calendar dynamically.

I have:

$('#calendar').fullCalendar({
                viewRender: function (view) {

                    var h;
                    if (view.name == "month") {
                        h = NaN;
                    }
                    else {
                        h = 2500; // high enough to avoid scrollbars
                    }


                    $('#calendar').fullCalendar('option', 'contentHeight', h);
                },
                lang: 'fr',
                events: [
                    {
                        title: '8 présents',
                        start: data[0]
                    },
                    {
                        title: '8 excusés',
                        start: data[1]
                    },
                    {
                        title: '8 excusés',
                        start: '2015-01-08'
                    },
                    {
                        title: '8 présents',
                        start: '2015-01-08'
                    },
                ],
                dayClick: function (date, jsEvent, view) {
                    window.location.replace(Routing.generate('dateChoisie', {date: date.format()}));
                }
            })

I have a var data, which is an array that contains all the dates of the events. I want to insert this in the events in the same way I inserted data[0], data[1], etc, but dynamically for all the dates.

I have tried to do a for:

events: [
    for (var i = 0, max = data.Lenght; i < max; i++) {
         {
                 title: '8 présents',
                 start: data[i]
           },
    }
                                {
                                    title: '8 excusés',
                                    start: data[1]
                                },
                                {
                                    title: '8 excusés',
                                    start: '2015-01-08'
                                },
                                {
                                    title: '8 présents',
                                    start: '2015-01-08'
                                },
                            ],

But it doesn't work inside the list.

Anybody know how I can do this?

like image 478
anubis Avatar asked Jan 13 '15 10:01

anubis


1 Answers

Source: http://fullcalendar.io/docs/event_data/addEventSource/

You can dynamically add an event source. An Event Source is an url which can for example return json data.

Maybe it might be sufficient for you to fire the refetch event after you changed the event data.

.fullCalendar( 'refetchEvents' )

Source: http://fullcalendar.io/docs/event_data/refetchEvents/

like image 64
Marcel Burkhard Avatar answered Sep 22 '22 20:09

Marcel Burkhard