Add Italian holidays into fullcalendar

前端 未结 1 580
挽巷
挽巷 2021-01-22 00:50

I use FullCalendar in my application and its working.

Now I need to change the color of Italian holidays into red. I did it for weekends but:

  1. I don\'t kn
相关标签:
1条回答
  • 2021-01-22 01:54

    You should use another eventSource that provides the holidays. These events can have a property like holiday, that specify that the event is indeed a holiday.

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

    You will have 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":"Christmas","start":"2014-12-25","holiday":"1"},{"title":"Another holiday","start":"2014-10-14","holiday":"1"}]

    0 讨论(0)
提交回复
热议问题