I was using resources well in fullcalendar version 3. I'm moving to version 4 and had some breaking changes. I can get the calendar to show my events properly but once I start to add resources, I get this error in my console:
main.js:145 Uncaught TypeError: Cannot read property 'ResourceDayGrid' of undefined
Code:
document.addEventListener('DOMContentLoaded', function() {
var calendar_full = document.getElementById('calendar_full');
var calendar = new FullCalendar.Calendar(calendar_full, {
selectMirror: true,
plugins: ['interaction', 'resourceDayGrid', 'resourceTimeGrid'],
header: {
right: 'prevYear,prev,next,today,nextYear',
center: 'title',
left: 'resourceTimeGridDay,resourceTimeGridTwoDay,timeGridWeek,dayGridMonth'
},
views: {
resourceTimeGridTwoDay: {
type: 'resourceTimeGrid',
duration: {
days: 2
},
buttonText: '2 days',
}
},
defaultView: 'resourceTimeGridDay',
datesAboveResources: true,
editable: true,
slotDuration: "<?php echo $location->data()->calendar_slot_duration; ?>",
snapDuration: "<?php echo $location->data()->calendar_snap_duration; ?>",
nowIndicator: true,
minTime: "<?php echo $location->data()->calendar_start; ?>",
maxTime: "<?php echo $location->data()->calendar_end; ?>",
hiddenDays: $.parseJSON('[' + "<?php echo $location->data()->calendar_hide_days_of_week; ?>" + ']'),
// groupByResource: true,
eventLimit: true,
schedulerLicenseKey: 'CC-Attribution-NonCommercial-NoDerivatives',
events: {
url: 'ajax_get_json.php?what=location_appointments'
},
resources: [{
id: '1',
title: 'Room A'
},
{
id: '2',
title: 'Room B'
}
]
});
calendar.render();
})
Here's an event JSON response example:
allDay: false
color: "#FFD700"
company_id: "1"
date_created: "2018-12-05 09:35:32"
start: "2019-04-30 14:00:00"
end: "2019-04-30 14:00:00"
id: "22218"
resourceId: "1"
If I change the default view to something that doesn't rely on resources, the calendar DOES show with all events. So this will render the calendar:
defaultView: 'dayGridMonth'
When I use defaultViews that use resources, I get the error.
Not sure how to troubleshoot this.
UPDATED TO ADD FOLLOWING SCRIPT INCLUDES:
<link href="added-assets/plugins/fullcalendar-4.0.2/packages/core/main.css" rel="stylesheet" />
<link href="added-assets/plugins/fullcalendar-4.0.2/packages/daygrid/main.css" rel="stylesheet" />
<link href="added-assets/plugins/fullcalendar-4.0.2/packages/timegrid/main.css" rel="stylesheet" />
<script src="added-assets/plugins/fullcalendar-4.0.2/packages/core/main.js" type="text/javascript"></script>
<script src="added-assets/plugins/fullcalendar-4.0.2/packages/daygrid/main.js" type="text/javascript"></script>
<script src="added-assets/plugins/fullcalendar-4.0.2/packages/interaction/main.js" type="text/javascript"></script>
<script src="added-assets/plugins/fullcalendar-4.0.2/packages/timegrid/main.js" type="text/javascript"></script>
<script src="added-assets/plugins/fullcalendar-4.0.2/packages/resource-common/main.js" type="text/javascript"></script>
<script src="added-assets/plugins/fullcalendar-4.0.2/packages/resource-timegrid/main.js" type="text/javascript"></script>
<script src="added-assets/plugins/fullcalendar-4.0.2/packages/resource-daygrid/main.js" type="text/javascript"></script>
ALSO, if it helps: I traced the error to the following line from the console error (the ResourceDayGrid function has the error):
_this.resourceTimeGrid = new ResourceTimeGrid(context, _this.timeGrid);
if (_this.dayGrid) {
_this.resourceDayGrid = new resourceDaygrid.ResourceDayGrid(context, _this.dayGrid);
}