Data binding
The Eventcalendar accepts an array of event objects through the data option of the component. The event array can be either a local static array, or populated on demand with remote requests.
Event data structure
The events of the Eventcalendar are specified as an array of event objects. The event object supports the following properties:
idString, Number - A unique id for the event. If not specifed, the event will get a generated id.startDate, String, Object - Specifies the start of the event.endDate, String, Object - Specifies the end of the event.titleString - The title of the event.colorString - The color of the event.allDayBoolean - Specifies if the event is all day or not.editableBoolean - specify if an event is editable or not. Setting it to false disables drag & drop, resize and delete, and the event will have the.mbsc-readonly-eventcss class. With this class, the fixed events will be easily customizable, for example: add opacity or disable the cursor on the fixed events.dragBetweenResourcesBoolean - specifies whether the event is movable across resources. It applies for scheduler and timeline views. Has precedence over theeventDragBetweenResourcesproperty of the resource and thedragBetweenResourcesoption.dragInTimeBoolean - specifies whether the event is movable in time. Has precedence over theeventDragInTimeproperty of the resource and thedragInTimeoption.resizeBoolean - specifies whether the event is resizable. Has precedence over theeventResizeproperty of the resource and thedragToResizeoption.resourceString, Number, Array - specify resource ids for the events. The event will display only in the specified resource group. If there is no resource id defined the event will be displayed at every resource group.slotString, Number - specify slot ids for the events. The event will display only in the specifiedslotgroup. If there is no slot id defined the event will be displayed at every slot group.recurringString, Object - Recurrence rule for the event.recurringExceptionString, Object, Array - Represents the exceptions of a recurring event. Useful when specific dates need to be skipped from the rule.recurringExceptionRuleString, Object - Represents the exception rule of a recurring event. Useful when recurring dates need to be skipped from the rule.timezoneString - The timezone of the event. When specified, it takes precedence overdataTimezone. A timezone plugin must be also passed to the component.tooltipString - Specifies the tooltip text of the event.cssClassString - Can be used to pass custom CSS classes on an event to event basis. Useful when customization is needed on the event level. For example: setting the width for specific events.bufferBeforeNumber - Defines a buffer time in minutes that will be displayed before the start of the event. This buffer area can help you visualise delays or added minutes for tasks. For example travel time for meetings/appointments, briefing before flight, check in time on duty card.bufferAfterNumber - Defines a buffer time in minutes that will be displayed after the end of the event. This buffer area can help you visualise delays or added minutes for tasks. For example travel time after meetings/appointments, debriefing after flight, check out time on duty card.
const myMeeting = {
start: "2023-07-14T08:00",
end: "2023-07-14T09:00",
title: "Meeting with Jenny",
};
The dates in the above structure can be specified as JavaScript Date objects, ISO 8601 strings, or moment objects.
const myBirthday = {
start: new Date(1988, 5, 28), // 1988 June 28th
allDay: true,
recurring: {
repeat: "yearly",
},
title: "My Birthday",
};
For Javascript Date objects the month numbers are zero based. Like: 0 - January, 1 - February ... 11 - December.
The event objects may have additional custom properties as well. The custom properties are not used by the eventcalendar, but they are kept and will be available anywhere the event objects are used. E.g. the onEventClick event will receive the event object as argument, containing the custom properties as well.
const weeklyMeeting = {
start: '2023-07-26T15:45',
end: '2023-07-26T16:00',
title: 'Daily summary',
address: 'Main Street 64'
videoUrl: 'https://myaddress.com/location',
recipients: ['Jack', 'Sam', 'Teal`c']
}
Recurring events
The recurring, recurringException and recurringExceptionRule properties of the event object are used to define events that happen again over time. Check out the recurrence section for a more comprehensive description on recurring rules.
Local data
To bind local data to the event calendar, you can simply assign a JavaScript array of objects to the data option of the component.
import { Eventcalendar } from "@mobiscroll/react";
const myData = [
{
id: "event_id1",
start: "2023-07-09",
end: "2023-07-13",
title: "My First Event",
},
{
id: "event_id2",
start: "2023-08-01",
end: "2023-08-03",
title: "My Second Event",
},
];
function App() {
return <Eventcalendar data={myData} />
}
Remote data
You can load the data through an external request and assign it to the data option of the component.
import { useEffect, useState } from "react";
import { Eventcalendar, getJson } from "@mobiscroll/react";
const MYVIEW = {
calendar: { type: "month" },
agenda: { type: "month" },
};
function App() {
const [events, setEvents] = useState([]); // store events in the state
// after render get the event data
useEffect(() => {
getJson(
"https://trial.mobiscroll.com/events/?vers=5",
(events) => {
setEvents(events); // put the returned events into the state
},
"jsonp"
);
});
return <Eventcalendar view={MYVIEW} data={events} />
}
On demand loading
Use the onPageLoading event to load the data relevant to the currently active view. The event fires every time the date range of the view changes, for example when someone navigates the event calendar. Getting the events in real time as the user interacts with the UI improves load performance and always serves the most recent data.
You can pass the view variables - like month and year - in the URL and handle the filtering inside the API implementation.
import { useCallback, useState } from 'react'
import { Eventcalendar, getJson } from '@mobiscroll/vue'
const MY_VIEW = {
schedule: { type: 'day' }
};
function App() {
const [myEvents, setEvents] = useState([]);
const myLoadPage = useCallback((args) => {
const year = args.month.getFullYear();
const month = args.month.getMonth();
const day = args.month.getDate();
getJson(
'https://trial.mobiscroll.com/weeklyevents/?year=' + year + '&month=' + month + '&day=' + day,
(data) => {
setEvents(data);
},
'jsonp'
)
}, []);
return <Eventcalendar data={myEvents} onPageLoading={myLoadPage} view={MY_VIEW} />
}
In case of the timeline view, data can also be loaded dynamically during scrolling. Scrolling vertically or horizontally triggers the onVirtualLoading lifecycle event, which can be used to load data incrementally during scrolling.