Add italian holidays to fullcalendar

I use FullCalendar in my application and its work.

Now I need to change the color of the Italian holidays to red. I did it on the weekend, but:

  • I do not know how to add holidays to the calendar.
  • How can I change my color.

This is my code:

<script>
    var calendar = $('#calendar').fullCalendar({
        header: {
            left: 'prev',
            center: 'title',
            right: 'next',
        },
        defaultView: 'month',
        lang: 'it',
        height: 600,
        dayClick: function(date, jsEvent, view) {
            // Changing BG color
            $(this).css('background-color', 'green');
            //Create modal here
            $('#myModal').modal();
            // Show Date in SPAN
            $('#spnDate').html(date.format('DD/MM/YYYY'));
            // Put Date value in a variable 
            $('#date').attr('value', date.format('DD/MM/YYYY'));

        },
        editable: true,
    });
</script>
+1
source share
1 answer

You must use another eventSourcethat provides holidays. These events may have a type property holidaythat indicates that the event is indeed a holiday.

Based on this holiday, you can change the background color of the day witheventRender

You need to add the following code to var calendar = $('#calendar').fullCalendar({:

eventSources: [
    {
        url: 'fullcalendar/holidays' // url to get holiday events
    }
    // any other sources...
],
eventRender: function(event, element, view) {
    // lets test if the event has a property called holiday. 
    // If so and it matches '1', change the background of the correct day
    if (event.holiday == '1') {
        var dateString = event.start.format("YYYY-MM-DD");

        $(view.el[0]).find('.fc-day[data-date=' + dateString + ']')
                        .css('background-color', '#FAA732');
    }
},

Your JSON object should look like this:

[{ "title": "", "": "2014-12-25", "": "1" }, { "title": " ", "": "2014 -10-14", "": "1" }]

+5

Source: https://habr.com/ru/post/1695035/


All Articles