To achieve a repeating background color pattern in FullCalendar without creating an event for each day, you can use the dayRender or dayCellDidMount callback (depending on the version of FullCalendar you are using) to dynamically set the background color of each cell based on the date. Since you have a repeating 4-day pattern, you can use the modulo operator to determine which group's color should be applied to a given day.
Here's an example of how you might implement this in FullCalendar v6:
document.addEventListener('DOMContentLoaded', function() {
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
headerToolbar: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay,listMonth'
},
initialDate: '2024-04-12',
navLinks: true,
businessHours: true,
editable: true,
selectable: true,
dayCellDidMount: function(dayCellMountArg) {
// Define your shift start date
var shiftStartDate = new Date('2024-04-01');
// Calculate the difference in days from the shift start date
var diffTime = Math.abs(dayCellMountArg.date - shiftStartDate);
var diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
// Use modulo to find the repeating pattern
var shift = diffDays % 4;
// Define your colors
var colors = ['#ff9f89', '#89a7ff', '#a0ff89', '#fffb89'];
// Set the background color based on the shift
dayCellMountArg.el.style.backgroundColor = colors[shift];
},
events: [
// Your existing events here
]
});
calendar.render();
});
In this code, dayCellDidMount is a callback that gets called after a day cell is mounted to the DOM. We calculate the difference in days from a defined start date (shiftStartDate) and use the modulo operator to determine which shift it is. Then, we apply the corresponding background color from the colors array.
Please note that the dayCellDidMount function is called for each day cell in the calendar view, so this will dynamically set the background color for each day without the need to create individual events for each shift. Adjust the shiftStartDate and colors array as needed for your specific use case.