Calendar
Bootstrap 5 Calendar plugin
MDB calendar is a plugin that allows you to efficiently manage tasks. Thanks to this extension you will be able to easily create new events, manage current events, move existing events between other days, and store all data in an easily readable array.
Responsive Calendar plugin built with the latest Bootstrap 5. Various customization options like default view, event formats, customizable captions, and much more.Note: Read the API tab to find all available options and advanced customization
Note: Currently, the plugin is only compatible with the basic MDB package imported in UMD format. More about import MDB formats.
Basic example
Several predefined events provide a visual representation of how the plugin appears."
<div class="calendar" data-mdb-calendar-init id="calendar"></div>
const events = [
{
summary: 'JS Conference',
start: {
date: Calendar.dayjs().format('DD/MM/YYYY'),
},
end: {
date: Calendar.dayjs().format('DD/MM/YYYY'),
},
color: {
background: '#cfe0fc',
foreground: '#0a47a9',
},
},
{
summary: 'Vue Meetup',
start: {
date: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY'),
},
end: {
date: Calendar.dayjs().add(5, 'day').format('DD/MM/YYYY'),
},
color: {
background: '#ebcdfe',
foreground: '#6e02b1',
},
},
{
summary: 'Angular Meetup',
description: 'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur',
start: {
date: Calendar.dayjs().subtract(3, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().subtract(3, 'day').format('DD/MM/YYYY') + ' 10:00',
},
end: {
date: Calendar.dayjs().add(3, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(3, 'day').format('DD/MM/YYYY') + ' 14:00',
},
color: {
background: '#c7f5d9',
foreground: '#0b4121',
},
},
{
summary: 'React Meetup',
start: {
date: Calendar.dayjs().add(5, 'day').format('DD/MM/YYYY'),
},
end: {
date: Calendar.dayjs().add(8, 'day').format('DD/MM/YYYY'),
},
color: {
background: '#fdd8de',
foreground: '#790619',
},
},
{
summary: 'Meeting',
start: {
date: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY') + ' 8:00',
},
end: {
date: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY') + ' 12:00',
},
color: {
background: '#cfe0fc',
foreground: '#0a47a9',
},
},
{
summary: 'Call',
start: {
date: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY') + ' 11:00',
},
end: {
date: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY') + ' 14:00',
},
color: {
background: '#292929',
foreground: '#f5f5f5',
},
}
];
const calendarElement = document.getElementById('calendar');
const calendarInstance = Calendar.getInstance(calendarElement);
calendarInstance.addEvents(events);
Event formats
Calendar events can be added with time in two different formats - 12h or 24h. Optionally, you can also use the dayjs static getter which returns the current date object. We recommend reading the dayjs library documentation before using this method.
{
summary: 'Call',
description: 'Agree the terms of contracts',
start: {
date: '08/09/2020',
dateTime: '08/09/2020 10:00',
},
end: {
date: '08/09/2020',
dateTime: '08/09/2020 14:00',
},
color: {
background: '#292929',
foreground: '#f5f5f5',
},
}
{
summary: 'Call',
description: 'Agree the terms of contracts',
start: {
date: '08/09/2020',
dateTime: '08/09/2020 10:00 AM',
},
end: {
date: '08/09/2020',
dateTime: '08/09/2020 02:00 PM',
},
color: {
background: '#292929',
foreground: '#f5f5f5',
},
}
{
summary: 'Call',
description: 'Agree the terms of contracts',
start: {
date: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY') + ' 11:00',
},
end: {
date: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY') + ' 14:00',
},
color: {
background: '#292929',
foreground: '#f5f5f5',
},
}
Monday first
Set the data-mdb-monday-first
attribute to true
to designate Monday as the first day of the week
<div class="calendar" id="calendar-2" data-mdb-calendar-init data-mdb-monday-first="true"></div>
const events = [
{
summary: 'JS Conference',
start: {
date: Calendar.dayjs().format('DD/MM/YYYY'),
},
end: {
date: Calendar.dayjs().format('DD/MM/YYYY'),
},
color: {
background: '#cfe0fc',
foreground: '#0a47a9',
},
},
{
summary: 'Vue Meetup',
start: {
date: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY'),
},
end: {
date: Calendar.dayjs().add(5, 'day').format('DD/MM/YYYY'),
},
color: {
background: '#ebcdfe',
foreground: '#6e02b1',
},
},
{
summary: 'Angular Meetup',
description: 'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur',
start: {
date: Calendar.dayjs().subtract(3, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().subtract(3, 'day').format('DD/MM/YYYY') + ' 10:00',
},
end: {
date: Calendar.dayjs().add(3, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(3, 'day').format('DD/MM/YYYY') + ' 14:00',
},
color: {
background: '#c7f5d9',
foreground: '#0b4121',
},
},
{
summary: 'React Meetup',
start: {
date: Calendar.dayjs().add(5, 'day').format('DD/MM/YYYY'),
},
end: {
date: Calendar.dayjs().add(8, 'day').format('DD/MM/YYYY'),
},
color: {
background: '#fdd8de',
foreground: '#790619',
},
},
{
summary: 'Meeting',
start: {
date: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY') + ' 8:00',
},
end: {
date: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY') + ' 12:00',
},
color: {
background: '#cfe0fc',
foreground: '#0a47a9',
},
},
{
summary: 'Call',
start: {
date: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY') + ' 11:00',
},
end: {
date: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY') + ' 14:00',
},
color: {
background: '#292929',
foreground: '#f5f5f5',
},
}
];
const calendarElement = document.getElementById('calendar-2');
const calendarInstance = Calendar.getInstance(calendarElement);
calendarInstance.addEvents(events);
Default view
Set the data-mdb-default-view
attribute to week
or
list
to change the start view. By default, it is a month
.
<div class="calendar" id="calendar-3" data-mdb-calendar-init data-mdb-default-view="week"></div>
const events = [
{
summary: 'JS Conference',
start: {
date: Calendar.dayjs().format('DD/MM/YYYY'),
},
end: {
date: Calendar.dayjs().format('DD/MM/YYYY'),
},
color: {
background: '#cfe0fc',
foreground: '#0a47a9',
},
},
{
summary: 'Vue Meetup',
start: {
date: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY'),
},
end: {
date: Calendar.dayjs().add(5, 'day').format('DD/MM/YYYY'),
},
color: {
background: '#ebcdfe',
foreground: '#6e02b1',
},
},
{
summary: 'Angular Meetup',
description: 'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur',
start: {
date: Calendar.dayjs().subtract(3, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().subtract(3, 'day').format('DD/MM/YYYY') + ' 10:00',
},
end: {
date: Calendar.dayjs().add(3, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(3, 'day').format('DD/MM/YYYY') + ' 14:00',
},
color: {
background: '#c7f5d9',
foreground: '#0b4121',
},
},
{
summary: 'React Meetup',
start: {
date: Calendar.dayjs().add(5, 'day').format('DD/MM/YYYY'),
},
end: {
date: Calendar.dayjs().add(8, 'day').format('DD/MM/YYYY'),
},
color: {
background: '#fdd8de',
foreground: '#790619',
},
},
{
summary: 'Meeting',
start: {
date: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY') + ' 8:00',
},
end: {
date: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY') + ' 12:00',
},
color: {
background: '#cfe0fc',
foreground: '#0a47a9',
},
},
{
summary: 'Call',
start: {
date: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY') + ' 11:00',
},
end: {
date: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY') + ' 14:00',
},
color: {
background: '#292929',
foreground: '#f5f5f5',
},
}
];
const calendarElement = document.getElementById('calendar-3');
const calendarInstance = Calendar.getInstance(calendarElement);
calendarInstance.addEvents(events);
Twelve hour
By setting the data-mdb-twelve-hour
attribute to true
, you get a 12-hour
schedule.
<div class="calendar" id="calendar-4" data-mdb-calendar-init data-mdb-default-view="week" data-mdb-twelve-hour="true"></div>
const events = [
{
summary: 'JS Conference',
start: {
date: Calendar.dayjs().format('DD/MM/YYYY'),
},
end: {
date: Calendar.dayjs().format('DD/MM/YYYY'),
},
color: {
background: '#cfe0fc',
foreground: '#0a47a9',
},
},
{
summary: 'Vue Meetup',
start: {
date: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY'),
},
end: {
date: Calendar.dayjs().add(5, 'day').format('DD/MM/YYYY'),
},
color: {
background: '#ebcdfe',
foreground: '#6e02b1',
},
},
{
summary: 'Angular Meetup',
description: 'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur',
start: {
date: Calendar.dayjs().subtract(3, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().subtract(3, 'day').format('DD/MM/YYYY') + ' 10:00 AM',
},
end: {
date: Calendar.dayjs().add(3, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(3, 'day').format('DD/MM/YYYY') + ' 02:00 PM',
},
color: {
background: '#c7f5d9',
foreground: '#0b4121',
},
},
{
summary: 'React Meetup',
start: {
date: Calendar.dayjs().add(5, 'day').format('DD/MM/YYYY'),
},
end: {
date: Calendar.dayjs().add(8, 'day').format('DD/MM/YYYY'),
},
color: {
background: '#fdd8de',
foreground: '#790619',
},
},
{
summary: 'Meeting',
start: {
date: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY') + ' 8:00 AM',
},
end: {
date: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY') + ' 12:00 PM',
},
color: {
background: '#cfe0fc',
foreground: '#0a47a9',
},
},
{
summary: 'Call',
start: {
date: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY') + ' 11:00 AM',
},
end: {
date: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY') + ' 02:00 PM',
},
color: {
background: '#292929',
foreground: '#f5f5f5',
},
}
];
const calendarElement = document.getElementById('calendar-4');
const calendarInstance = Calendar.getInstance(calendarElement);
calendarInstance.addEvents(events);
Customize pickers
You can customize datepicker
and timepicker
displayed in the calendar changing options
availible in the API tab of respected pickers.
<div id="calendar-with-custom-pickers"></div>
const events = [
{
summary: 'JS Conference',
start: {
date: Calendar.dayjs().format('DD/MM/YYYY'),
},
end: {
date: Calendar.dayjs().format('DD/MM/YYYY'),
},
color: {
background: '#cfe0fc',
foreground: '#0a47a9',
},
},
{
summary: 'Vue Meetup',
start: {
date: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY'),
},
end: {
date: Calendar.dayjs().add(5, 'day').format('DD/MM/YYYY'),
},
color: {
background: '#ebcdfe',
foreground: '#6e02b1',
},
},
{
summary: 'Angular Meetup',
description: 'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nullpariatur',
start: {
date: Calendar.dayjs().subtract(3, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().subtract(3, 'day').format('DD/MM/YYYY') + ' 10:00',
},
end: {
date: Calendar.dayjs().add(3, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(3, 'day').format('DD/MM/YYYY') + ' 14:00',
},
color: {
background: '#c7f5d9',
foreground: '#0b4121',
},
},
{
summary: 'React Meetup',
start: {
date: Calendar.dayjs().add(5, 'day').format('DD/MM/YYYY'),
},
end: {
date: Calendar.dayjs().add(8, 'day').format('DD/MM/YYYY'),
},
color: {
background: '#fdd8de',
foreground: '#790619',
},
},
{
summary: 'Meeting',
start: {
date: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY') + ' 8:00',
},
end: {
date: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY') + ' 12:00',
},
color: {
background: '#cfe0fc',
foreground: '#0a47a9',
},
},
{
summary: 'Call',
start: {
date: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY') + ' 11:00',
},
end: {
date: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY') + ' 14:00',
},
color: {
background: '#292929',
foreground: '#f5f5f5',
},
}
];
const calendarElement = document.getElementById('calendar-with-custom-pickers');
calendarElement.classList.add('calendar');
const calendarInstance = new Calendar(calendarElement, {
events: events,
timepickerOptions: {
clearLabel: "Example Clear",
},
datepickerOptions: {
okBtnText: "Example Ok",
}
});
Default date
A starting day can be easily set using the
data-mdb-default-date
attribute.
<div class="calendar" id="calendar-6" data-mdb-calendar-init data-mdb-default-date="01-12-2024"></div>
const events = [
{
summary: 'JS Conference',
start: {
date: Calendar.dayjs().format('DD/MM/YYYY'),
},
end: {
date: Calendar.dayjs().format('DD/MM/YYYY'),
},
color: {
background: '#cfe0fc',
foreground: '#0a47a9',
},
},
{
summary: 'Vue Meetup',
start: {
date: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY'),
},
end: {
date: Calendar.dayjs().add(5, 'day').format('DD/MM/YYYY'),
},
color: {
background: '#ebcdfe',
foreground: '#6e02b1',
},
},
{
summary: 'Angular Meetup',
description: 'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur',
start: {
date: Calendar.dayjs().subtract(3, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().subtract(3, 'day').format('DD/MM/YYYY') + ' 10:00',
},
end: {
date: Calendar.dayjs().add(3, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(3, 'day').format('DD/MM/YYYY') + ' 14:00',
},
color: {
background: '#c7f5d9',
foreground: '#0b4121',
},
},
{
summary: 'React Meetup',
start: {
date: Calendar.dayjs().add(5, 'day').format('DD/MM/YYYY'),
},
end: {
date: Calendar.dayjs().add(8, 'day').format('DD/MM/YYYY'),
},
color: {
background: '#fdd8de',
foreground: '#790619',
},
},
{
summary: 'Meeting',
start: {
date: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY') + ' 8:00',
},
end: {
date: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY') + ' 12:00',
},
color: {
background: '#cfe0fc',
foreground: '#0a47a9',
},
},
{
summary: 'Call',
start: {
date: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY') + ' 11:00',
},
end: {
date: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY') + ' 14:00',
},
color: {
background: '#292929',
foreground: '#f5f5f5',
},
}
];
const calendarElement = document.getElementById('calendar-6');
const calendarInstance = Calendar.getInstance(calendarElement);
calendarInstance.addEvents(events);
Readonly
The editable mode can be easily disabled using the
data-mdb-readonly
attribute.
<div class="calendar" id="calendar-7" data-mdb-calendar-init data-mdb-readonly="true"></div>
const events = [
{
summary: 'JS Conference',
start: {
date: Calendar.dayjs().format('DD/MM/YYYY'),
},
end: {
date: Calendar.dayjs().format('DD/MM/YYYY'),
},
color: {
background: '#cfe0fc',
foreground: '#0a47a9',
},
},
{
summary: 'Vue Meetup',
start: {
date: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY'),
},
end: {
date: Calendar.dayjs().add(5, 'day').format('DD/MM/YYYY'),
},
color: {
background: '#ebcdfe',
foreground: '#6e02b1',
},
},
{
summary: 'Angular Meetup',
description: 'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur',
start: {
date: Calendar.dayjs().subtract(3, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().subtract(3, 'day').format('DD/MM/YYYY') + ' 10:00',
},
end: {
date: Calendar.dayjs().add(3, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(3, 'day').format('DD/MM/YYYY') + ' 14:00',
},
color: {
background: '#c7f5d9',
foreground: '#0b4121',
},
},
{
summary: 'React Meetup',
start: {
date: Calendar.dayjs().add(5, 'day').format('DD/MM/YYYY'),
},
end: {
date: Calendar.dayjs().add(8, 'day').format('DD/MM/YYYY'),
},
color: {
background: '#fdd8de',
foreground: '#790619',
},
},
{
summary: 'Meeting',
start: {
date: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY') + ' 8:00',
},
end: {
date: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY') + ' 12:00',
},
color: {
background: '#cfe0fc',
foreground: '#0a47a9',
},
},
{
summary: 'Call',
start: {
date: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY') + ' 11:00',
},
end: {
date: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY') + ' 14:00',
},
color: {
background: '#292929',
foreground: '#f5f5f5',
},
}
];
const calendarElement = document.getElementById('calendar-7');
const calendarInstance = Calendar.getInstance(calendarElement);
calendarInstance.addEvents(events);
Readonly events
The editable mode for any event can be easily disabled by adding
readonly
attribute in the event's dataset.
<div class="calendar" data-mdb-calendar-init id="calendar-8"></div>
const events = [
{
summary: 'Readonly event',
start: {
date: Calendar.dayjs().format('DD/MM/YYYY'),
},
end: {
date: Calendar.dayjs().format('DD/MM/YYYY'),
},
color: {
background: '#cfe0fc',
foreground: '#0a47a9',
},
readonly: true
},
{
summary: 'Vue Meetup',
start: {
date: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY'),
},
end: {
date: Calendar.dayjs().add(5, 'day').format('DD/MM/YYYY'),
},
color: {
background: '#ebcdfe',
foreground: '#6e02b1',
},
},
{
summary: 'Readonly event',
description:
'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur',
start: {
date: Calendar.dayjs().subtract(3, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().subtract(3, 'day').format('DD/MM/YYYY') + ' 10:00',
},
end: {
date: Calendar.dayjs().add(3, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(3, 'day').format('DD/MM/YYYY') + ' 14:00',
},
color: {
background: '#c7f5d9',
foreground: '#0b4121',
},
readonly: true
},
{
summary: 'React Meetup',
start: {
date: Calendar.dayjs().add(5, 'day').format('DD/MM/YYYY'),
},
end: {
date: Calendar.dayjs().add(8, 'day').format('DD/MM/YYYY'),
},
color: {
background: '#fdd8de',
foreground: '#790619',
},
},
{
summary: 'Meeting',
start: {
date: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY') + ' 8:00',
},
end: {
date: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY') + ' 12:00',
},
color: {
background: '#cfe0fc',
foreground: '#0a47a9',
},
},
{
summary: 'Readonly event',
start: {
date: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY') + ' 11:00',
},
end: {
date: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY') + ' 14:00',
},
color: {
background: '#292929',
foreground: '#f5f5f5',
},
readonly: true
}
];
const calendarElement = document.getElementById('calendar-8');
const calendarInstance = Calendar.getInstance(calendarElement);
calendarInstance.addEvents(events);
Disabled modules
Some of the modules can be disabled via data attributes or JavaScript. Here's an example without tooltips and some toolbar action elements.
<div class="calendar" id="calendar-9" data-mdb-calendar-init data-mdb-tooltips="false" data-mdb-navigation="false" data-mdb-view-select="false" data-mdb-add-event-button="false"></div>
const events = [
{
summary: 'JS Conference',
start: {
date: Calendar.dayjs().format('DD/MM/YYYY'),
},
end: {
date: Calendar.dayjs().format('DD/MM/YYYY'),
},
color: {
background: '#cfe0fc',
foreground: '#0a47a9',
},
},
{
summary: 'Vue Meetup',
start: {
date: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY'),
},
end: {
date: Calendar.dayjs().add(5, 'day').format('DD/MM/YYYY'),
},
color: {
background: '#ebcdfe',
foreground: '#6e02b1',
},
},
{
summary: 'Angular Meetup',
description:
'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur',
start: {
date: Calendar.dayjs().subtract(3, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().subtract(3, 'day').format('DD/MM/YYYY') + ' 10:00',
},
end: {
date: Calendar.dayjs().add(3, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(3, 'day').format('DD/MM/YYYY') + ' 14:00',
},
color: {
background: '#c7f5d9',
foreground: '#0b4121',
},
},
{
summary: 'React Meetup',
start: {
date: Calendar.dayjs().add(5, 'day').format('DD/MM/YYYY'),
},
end: {
date: Calendar.dayjs().add(8, 'day').format('DD/MM/YYYY'),
},
color: {
background: '#fdd8de',
foreground: '#790619',
},
},
{
summary: 'Meeting',
start: {
date: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY') + ' 8:00',
},
end: {
date: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY') + ' 12:00',
},
color: {
background: '#cfe0fc',
foreground: '#0a47a9',
},
},
{
summary: 'Call',
start: {
date: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY') + ' 11:00',
},
end: {
date: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY') + ' 14:00',
},
color: {
background: '#292929',
foreground: '#f5f5f5',
},
}
];
const calendarElement = document.getElementById('calendar-9');
const calendarInstance = Calendar.getInstance(calendarElement);
calendarInstance.addEvents(events);
Blur
Past events can be blurred with the data-mdb-blur
attribute.
<div class="calendar" data-mdb-calendar-init id="calendar-10" data-mdb-blur="true"></div>
const events = [
{
summary: 'JS Conference',
start: {
date: Calendar.dayjs().format('DD/MM/YYYY'),
},
end: {
date: Calendar.dayjs().format('DD/MM/YYYY'),
},
color: {
background: '#cfe0fc',
foreground: '#0a47a9',
},
},
{
summary: 'Vue Meetup',
start: {
date: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY'),
},
end: {
date: Calendar.dayjs().add(5, 'day').format('DD/MM/YYYY'),
},
color: {
background: '#ebcdfe',
foreground: '#6e02b1',
},
},
{
summary: 'Angular Meetup',
description:
'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur',
start: {
date: Calendar.dayjs().subtract(3, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().subtract(3, 'day').format('DD/MM/YYYY') + ' 10:00',
},
end: {
date: Calendar.dayjs().add(3, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(3, 'day').format('DD/MM/YYYY') + ' 14:00',
},
color: {
background: '#c7f5d9',
foreground: '#0b4121',
},
},
{
summary: 'React Meetup',
start: {
date: Calendar.dayjs().add(5, 'day').format('DD/MM/YYYY'),
},
end: {
date: Calendar.dayjs().add(8, 'day').format('DD/MM/YYYY'),
},
color: {
background: '#fdd8de',
foreground: '#790619',
},
},
{
summary: 'Meeting',
start: {
date: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY') + ' 8:00',
},
end: {
date: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY') + ' 12:00',
},
color: {
background: '#cfe0fc',
foreground: '#0a47a9',
},
},
{
summary: 'Call',
start: {
date: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY') + ' 11:00',
},
end: {
date: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY') + ' 14:00',
},
color: {
background: '#292929',
foreground: '#f5f5f5',
},
}
];
const calendarElement = document.getElementById('calendar-10');
const calendarInstance = Calendar.getInstance(calendarElement);
calendarInstance.addEvents(events);
Custom attributes
You can add your own attributes to existing and new events. Below is an example
with the id
attribute.
<div id="calendar-11"></div>
const events = [
{
summary: 'JS Conference',
start: {
date: Calendar.dayjs().format('DD/MM/YYYY'),
},
end: {
date: Calendar.dayjs().format('DD/MM/YYYY'),
},
color: {
background: '#cfe0fc',
foreground: '#0a47a9',
},
id: 1
},
{
summary: 'Vue Meetup',
start: {
date: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY'),
},
end: {
date: Calendar.dayjs().add(5, 'day').format('DD/MM/YYYY'),
},
color: {
background: '#ebcdfe',
foreground: '#6e02b1',
},
id: 2
},
{
summary: 'Angular Meetup',
description:
'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur',
start: {
date: Calendar.dayjs().subtract(3, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().subtract(3, 'day').format('DD/MM/YYYY') + ' 10:00',
},
end: {
date: Calendar.dayjs().add(3, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(3, 'day').format('DD/MM/YYYY') + ' 14:00',
},
color: {
background: '#c7f5d9',
foreground: '#0b4121',
},
id: 3
},
{
summary: 'React Meetup',
start: {
date: Calendar.dayjs().add(5, 'day').format('DD/MM/YYYY'),
},
end: {
date: Calendar.dayjs().add(8, 'day').format('DD/MM/YYYY'),
},
color: {
background: '#fdd8de',
foreground: '#790619',
},
id: 4
},
{
summary: 'Meeting',
start: {
date: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY') + ' 8:00',
},
end: {
date: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(1, 'day').format('DD/MM/YYYY') + ' 12:00',
},
color: {
background: '#cfe0fc',
foreground: '#0a47a9',
},
id: 5
},
{
summary: 'Call',
start: {
date: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY') + ' 11:00',
},
end: {
date: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY'),
dateTime: Calendar.dayjs().add(2, 'day').format('DD/MM/YYYY') + ' 14:00',
},
color: {
background: '#292929',
foreground: '#f5f5f5',
},
id: 6
}
];
const calendarElement = document.getElementById('calendar-11');
calendarElement.classList.add('calendar');
let newEventId = events.length;
const calendarInstance = new Calendar(calendarElement, {
newEventAttributes: (event) => {
newEventId++;
return {
...event,
id: newEventId
}
}
});
calendarInstance.addEvents(events);
calendarElement.addEventListener('addEvent.mdb.calendar', (e) => {
console.log(e.event);
console.log(calendarInstance.events);
});
Calendar - API
Import
import Calendar from 'mdb-calendar';
@import '~mdb-calendar/css/calendar.min.css';
Usage
Via data attributes
Using the Calendar plugin doesn't require any additional JavaScript code - simply add
data-mdb-calendar-init
attribute to
.calendar
and use other data attributes to set all options.
<div class="calendar" data-mdb-calendar-init></div>
Via JavaScript
const element = document.querySelector('.calendar');
const instance = new Calendar(calendarElement);
Via jQuery
Note: By default, MDB does not include jQuery and you have to add it to the project on your own.
$(document).ready(() => {
$('#calendar').calendar('next');
});
Options
Options can be passed via data attributes or JavaScript. For data attributes, append the option name to
data-mdb-
, as in data-mdb-readonly=""
.
Name | Type | Default | Description |
---|---|---|---|
weekdays
|
Array | String | ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'] |
Defines weekdays displayed names. |
months
|
Array | String |
['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August',
'September', 'October', 'November', 'December']
|
Defines months displayed names. |
monthsShort
|
Array | String | ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] |
Defines shortened months displayed names. |
mondayFirst
|
Boolean | false |
Changes first day of week to monday. |
defaultView
|
String | 'month' |
Defines default view. |
twelveHour
|
Boolean | false |
Changes time mode from 24h to 12h. |
defaultDate
|
Object | String | dayjs() |
Defines the default starting date. |
readonly
|
Boolean | false |
Disables event's edition. |
todayCaption
|
String | 'Today' |
Defines caption for today. |
monthCaption
|
String | 'Month' |
Defines caption for month option. |
weekCaption
|
String | 'Week' |
Defines caption for week option. |
listCaption
|
String | 'List' |
Defines caption for list option. |
allDayCaption
|
String | 'All day event' |
Defines caption for all day event checkbox. |
noEventsCaption
|
String | 'No events' |
Defines caption for empty list view. |
summaryCaption
|
String | 'Summary' |
Defines caption for summary input label. |
descriptionCaption
|
String | 'Description' |
Defines caption for description input label. |
startCaption
|
String | 'Start' |
Defines caption for start input label. |
endCaption
|
String | 'End' |
Defines caption for end input label. |
addCaption
|
String | 'Add' |
Defines caption for add event button. |
deleteCaption
|
String | 'Remove' |
Defines caption for remove event button. |
saveCaption
|
String | 'Save' |
Defines caption for save event button. |
closeCaption
|
String | 'Close' |
Defines caption for close button. |
addEventCaption
|
String | 'Add event' |
Defines caption for button that trigger the add event modal. |
addEventModalCaption
|
String | 'Add an event' |
Defines caption for add event modal title. |
editEventModalCaption
|
String | 'Edit an event' |
Defines caption for edit event modal title. |
events
|
Array of Objects | [] |
Defines calendar events. |
tooltips
|
Boolean | true |
Enables tooltips. |
navigation
|
Boolean | true |
Enables navigation. |
viewSelect
|
Boolean | true |
Enables viewSelect. |
addEventButton
|
Boolean | true |
Enables addEventButton. |
blur
|
Boolean | false |
Enables past events blur style. |
newEventAttributes
|
Function | (event) => event |
Modifies new events attributes. |
datepickerOptions
|
Object | {} |
Allow setting custom options for datepicker displayed in the calendar. |
timepickerOptions
|
Object | {} |
Allow setting custom options for timepicker displayed in the calendar. |
dateFormat
|
String | 'DD/MM/YYY' |
Allow setting custom date format in the calendar. |
Methods
Name | Parameters | Description | Example |
---|---|---|---|
init |
Initializes the calendar. | instance.init() |
|
prev |
Changes the period of time to previous. | instance.prev() |
|
next |
Changes the period of time to next. | instance.next() |
|
today |
Changes the period of time to today. | instance.today() |
|
changeView
|
view | Changes the view. |
instance.changeView('week')
|
refresh
|
Refreshes the calendar. |
instance.refresh()
|
|
addEvents
|
events | Adds new events to the calendar. |
instance.addEvents([...])
|
removeEvents
|
Removes all events from the calendar. |
instance.removeEvents()
|
|
dispose
|
Disposes a calendar instance. |
instance.dispose()
|
|
dayjs |
Static method which returns a dayjs function. | Calendar.dayjs() |
|
getInstance
|
Static method which allows you to get the calendar instance associated with a DOM element. |
Calendar.getInstance(calendarElement)
|
const calendarElement = document.getElementById('calendar');
const instance = Calendar.getInstance(calendarElement);
instance.next();
Events
Name | Description |
---|---|
prev.mdb.calendar
|
Emitted when the prev method triggers. |
next.mdb.calendar
|
Emitted when the next method triggers. |
today.mdb.calendar
|
Emitted when the today method triggers. |
viewChange.mdb.calendar
|
Emitted when the changeView method triggers. |
update.mdb.calendar
|
Emitted when the refresh method triggers. |
addEvent.mdb.calendar
|
Emitted when a new event is added. Returns a new event object. |
editEvent.mdb.calendar
|
Emitted when any event is editted. Returns an editted event object. |
deleteEvent.mdb.calendar
|
Emitted when any event is deleted. Returns a deleted event object. |
window.addEventListener('next.mdb.calendar', () => {
alert('Time period changed'));
}