2

I need to add an event for all the sundays on my calendar. Is there any option available in FullCalendar?

day = 'Sunday'; <------ I need to pass this day to create event

var date = new Date();
var event = {id: result.id, title: from_time + '-' + to_time, start: new Date(date), allDay: false};
                  }
$('#calendar').fullCalendar('renderEvent', event, true);
DanielST
  • 13,783
  • 7
  • 42
  • 65
Deepanshu Goyal
  • 2,738
  • 3
  • 34
  • 61

3 Answers3

3

You can do this very simply with the dow event attribute. It's not documented very well but it's mentioned in backgroundEvents and businessHours. It lets you set the day of the week that the event will always occur on.

So something like this:

$("#calendar").fullCalendar({
    events:[{
        title:"Monday",
        dow:[1] //monday
        //start/endtime works too
    },{
        title:"background",
        dow:[2,3], //tuesday and wednesday
        rendering: 'background'
    }],
});

JSFiddle

And if you need something more complicated, like repeating events only within a certain date range, take a look at my answer here: https://stackoverflow.com/a/29393128/728393

Community
  • 1
  • 1
DanielST
  • 13,783
  • 7
  • 42
  • 65
0

Please find some reference code for event repeat.

 $('#calendar').fullCalendar( 'addEventSource',        
        function(start, end, callback) {
            // When requested, dynamically generate virtual
            // events for every sunday
            var events = [];

            for (loop = start.getTime();
                 loop <= end.getTime();
                 loop = loop + (24 * 60 * 60 * 1000)) {

                var test_date = new Date(loop);

                if (test_date.is().sunday()) {
                    // we're in Sunday, create the event
                    events.push({
                        title: 'I Love Sundays - Janty',
                        start: test_date
                    });
                }

            } // for loop

            // return events generated
            callback( events );
        }
    );

Repeat event every monday

Community
  • 1
  • 1
Janty
  • 1,708
  • 2
  • 15
  • 29
-2
events: [
              {
                  title:"Monday",
                  dow:[1] //monday
                  //start/endtime works too
              },{
                  title:"background",
                  *daysOfWeek*: [2, 3], //tuesday and wednesday
                  rendering: 'background'
              }]

daysOfWeek

...

Adriaan
  • 17,741
  • 7
  • 42
  • 75
Tehila
  • 1
  • 3
    Welcome to Stack Overflow! Thank you for your answer, but please keep in mind that you are not only answering to the OP. Adding some explanation as to why this code works, either as text around or comments in the code, would be very helpful to future readers. – Adriaan Apr 01 '19 at 09:15