How to create event calendar in html using javascript

Updated on Sep 13, 2022

Use it in responsive mobile & desktop web apps wherever Javascript runs.

Recurring events

Multi-day events

Popover with full event list

Drag & drop

Templating

Resource support

Customizable times

Drag & drop

Manage multiple resources

Daily, weekly or monthly timeline

Drag & drop

Customizable range

Scroll to date

Recurring events

Templating

Daily, weekly or monthly agenda

The calendar view supports everything from single to multiple week views all the way to month grids with various ways to render events.
The four views - scheduler, calendar, timeline, agenda - can be combined to create the perfect user experience on mobile, desktop and on everything in-between.

The capabilities like recurring events, all-day, multi-day events, responsiveness are supported by all views.

As part of Event calendar and scheduler it can be picked up with the Scheduling & calendaring and Complete licenses.

Browse the various components and demos

Close

Calendar - Mobile month view

Change demo

Use the event calendar for mobile, desktop and everything in-between. The content perfectly fills the parent container or the mobile screen in full width. You can chooose to render an agenda below the calendar broken up into days ordered chronologically. All of this is configured in the view option.

You can use the calendar and agenda together or separately. For more ways to use the agenda learn about how to configure it.

Interested to see how the event calendar looks on largers screens with labels?  Check out the next demo →

  • JS
  • HTML

Calendar - Desktop month view

Change demo

Desktops or larger screens provide more space, which means you can use not just the horizontal but vertical space as well. Horrizontally the calendar grows to fill the full width of the parent container while the height can be adjusted through the height option.

The number of visible labels are determined by the available space and the ones that don't fit will be shown in a popover. To save vertical space you can show all events in a popover.

  • JS
  • HTML

Calendar - Responsive

Change demo

The event calendar is fully responsive. It adapts to the available space and fills the screen to look good everywhere. While the you don't have to worry about the width the height can be manually adjusted with the height option.

Use the responsive option to configure how the calendar behaves on different sized screens. The responsive option is equipped with five breakpoints - xsmall [up to 575px], small [up to 767px], medium [up to 991px], large [up to 1199px], xlarge [from 1200px]. Custom breakpoints can be added if necessary: my-custom-breakpoint: { breakpoint: 600 } [from 600px up to the next breakpoint].

Change the viewport

375px 576px 768px 992px 1200px

Calendar - Print mode

Change demo

The event calendar includes print optimized styling through the print add-on. This needs to be added to the download package or installed separately from a dedicated NPM package.

Print styling is applied when someone prints the page that contains the calendar. In addition to that, you can call the print method on the instance which grabs only the markup of the calendar, places it onto a temporary page and calls the browsers printing function. This is especially useful when you want to add a button to only print the calendar rather than the whole page.

Besides printing, PDF export is possible though the print dialog of the browser.

The print module is not available in the trial. You can try the live demo to see how it looks.

Calendar - Events as labels

Change demo

Events can be displayed in a couple of different ways. Most of the time showing the event data inside and across the calendar cells is the way to go. When configuring the calendar object, you can set labels: true. All of this happens under the view option.

The number of visible labels are determined by the available space and the ones that don't fit will be shown in a popover. To save vertical space you can show all events in a popover.

  • JS
  • HTML

Calendar - Events in popover

Change demo

Besides displaying events as labels, you can have them show up in a pop-over. Set it up though the calendar: {popover: true} object inside the view option. Using the popover setting saves vertical space and provides a subtle cue to the user that there are events. A small dot will apear in day cells with events or if calendar: {count: true} is set, an event count is displayed.

The same popover is rendered when events are displayed as labels and not all fit vertically in the calendar day cells.

  • JS
  • HTML

Calendar - Custom event order

Change demo

When rendering events, they follow the same order: all-day events at the top followed by everything else sorted by the event start time. Events with the same start are ordered alphabetically by title.

The default logic can be overriden using the eventOrder option which expects a function that compares two events and returns an order [-1 or 1]. This can be useful in scenario where rendering PROPOSED vacation at the top followed by APPROVED time off is more useful.

  • JS
  • HTML

Calendar - Timezones

Change demo

The event calendar works with local times by default, but ships with support for changing the timezone. The conversions and correct output relies on either of the two external libraries: luxon or moment-timezone. For installing and using these libraries check out this guide.

There are two angles regarding timezones:

  • dataTimezone - the calendar expects this format and returns this format. It is 'local' by default if the date-times don't contain any timezone information
  • displayTimezone - the calendar displays the events in this timezone. The date-times will be converted from the dataTimezone and displayed accordingly. It is 'local' by default

Calendar - Switching timezones

Change demo

If the context requires users being able to change the timezone on the fly, you can add a custom dropdown with the desired timezones to the event calendar header. This can be of course placed externally to the calendar as well, eg. setting page.

Set the timezone of the incoming data through the dataTimezone - eg. 'utc', and set the display timezone thorugh the displayTimezone - eg. 'America/Los_Angeles'

  • JS
  • HTML
  • CSS

Calendar - Month or week view

Change demo

The calendar view supports variable weeks. Save space by only displaying one or two weeks or go for a full month where it makes sense. Use the type and size properties of the view option to set the size of the month or week view.

Calendar - Multi-month or year view

Change demo

Besides the single month view, the calendar can be configured to render multiple months or a year. Controlled thorugh the calendar.type and calendar.size properties of the view option.

Depending on the height of the parent container the calendar is rendered in, the header that can be used for navigation is sticky at the top while the months are vertically scrollable.

  • JS
  • HTML
  • CSS

Calendar - Displaying labels

Change demo

Labels on the event calendar go hand in hand with the height of the event calendar rows [representing weeks]. It is possible to render as many lables as fit and keep the row heights equal. The row height is liquid and determined by the height of the calendar.

If you would like to render all labels, then passing labels: 'all' will do just that. This can make the row heights variable.

Alternatively a maximum number of labels can be set by passing a number to the labels property of the view.calendar option.

If there are more events than the number of labels for a particular day, an "x more" label will help users list out all events for the day.

Calendar - Colored backgrounds

Change demo

  • JS
  • HTML

Calendar - Switching views

Change demo

Dynamically switch views within one calendar instance. Use a UI control to let users do the switching or do it programatically. This example features a segmented component inside the header, but the live option changes can be invoked from anywhere.

Switch between a month view with a monthly agenda, a week view with a weekly agenda and daily event list. Use the setOptions method to dynamically update any option.

  • JS
  • HTML
  • CSS

Calendar - Custom event labels

Change demo

You can customize the look of the labels and show addtional content besides the event.title. There are two approached you can take:

  • Only customize the content of the labels - For this you will want to use the renderLabelContent option. The color and positioning of the label will be handled by the calendar. The title and any other custom fields you want to show inside the label is your responsability.
  • Fully customize how the labels look [like in this example] - Use the renderLabel option. All original event fields along with computed fields like isMultiDay, lastDay can be leveraged for constructing the render function. With the renderLabel you will have full control over how the labels are styled including things like color, title and any custom fields.

  • JS
  • HTML
  • CSS

Calendar - Custom events in popover

Change demo

The events listed in the popover can be customized in two ways:

  • Full event customization [like in this example] - The calendar handles the rendering of events in the correct order. Styling the content, colors and everything else is your responsability.
  • Content customization - The calendar prints the start and end times, allDay and sets the appropriate color. Content like title and other fields can be shown.

You can provide styling to the title field and any other custom fields like description, location, participants ...

Pass a rendering function to the renderEventContent option. All original event fields along with computed fields like isMultiDay, lastDay are passed to the function. For a fully custom event rendering use the renderEvent option.

If you add custom markup you will want to add styling too. Use the popoverClass under the view option to tell the calendar what CSS class it should append to the popover container so that you can write specific CSS rules.

  • JS
  • HTML
  • CSS

Calendar - Customizing the header

Change demo

You can customize how the header of the event calendar looks and how the components are arranged. Besides that you can also add custom functionality, like a segmented control that lets people switch between calendar and scheduler.

Use the renderHeader option for passing a custom header layout. There are predefined components - shorthands if you will - that can be used to assemble the header:

  • Navigation component -
    . Use the .md-header-filter-controls CSS class for custom overrides.
  • Today button - . Use the .md-header-filter-today CSS class for custom overrides.
  • Previous month button - . Use the .md-header-filter-prev CSS class for custom overrides.
  • Next month button - . Use the .md-header-filter-next CSS class for custom overrides.

For changing the order the controls are laid out, you only need to set up the renderHeader. This example sets a consistent order and layout across all themes and shows a custom control at the far right end.

Overriding the order for specific themes

For a custom order on a theme to theme basis, you will need to use a little CSS. Flex layout makes reordering easy. It's just a matter of setting the order in CSS. For material use the .mbsc-material, for windows the .mbsc-windows prefix and for iOS it is .mbsc-ios class. Eg.:

.mbsc-material .md-header-filter-prev { order: 1; }
.mbsc-material .md-header-filter-next { order: 2; }
.mbsc-material .md-header-filter-controls { order: 3; }
.mbsc-material .md-header-filter-today { order: 4; }

  • JS
  • HTML
  • CSS

Calendar - Custom event tooltip

Change demo

There are several approaches to showing a tooltip when hovering events.

The native tooltip

By default, the calendar shows the browser native tooltip when hovering the event. This includes the times and title of the event, which does the job most of the times. For showing a custom text use the tooltip property of the data object. This tooltip is specific to every event. If you want to hide the native tooltip, you can set the showEventTooltip to false.

Fully custom tooltip

Setting the showEventTooltip to false gives room for a fully custom tooltip that can be implemented by using the onEventHoverIn and onEventHoverOut lifecycle events. With the help of the Mobiscroll popup you can show a custom tooltip that holds details, actions applicable to the event it is anchored to.

  • JS
  • HTML
  • CSS

Calendar - Move, resize & create

Change demo

Drag & drop is a core feature of the event calendar and it is composed of four sub-features:

  • Click to create events - double click to create events. This can be turned off or set to single click
  • Drag to create events - tap/click to start creating an event and drag to the desired length
  • Move events - grab an event and move it wherever needed
  • Resize events - change the length of en event, grab it from either end and resize it
  • Delete events - pressing the Delete or Backspace keys on the keyboard will delete the focused event

You have granular control over features through the clickToCreate, dragToCreate, dragToMove, dragToResize and eventDelete options, which are false by default.

Events can be marked as fixed by setting their editable property to false. This turns delete, drag & drop move and resize off for the event. The mbsc-event-readonly CSS class will be added to the events. This means if you would like to add opacity, override the mouse cursor or apply any other CSS override, you can add it to this class.

Calendar - Manage blocked out dates

Change demo

Entire days and ranges can blocked out to manage event creation and editing more efficiently.

To disable specific or recurring days you can pass an array to the invalid option. A couple of examples:

  • To disable weekends, use the recurring object - recurring: { repeat: 'weekly', weekDays: 'SA,SU' }
  • Disable a specific range - { start: new Date[2020, 11, 19], end: new Date[2020, 11, 20] }

When dragging events onto disabled days, they will automatically be denied and onEventCreateFailed/ onEventUpdateFailed events will be triggered, from which custom logic can be executed to show a toast or maybe a modal for data correction. The built-in logic of how the calendar handles validation on user interaction can be controlled through the invalidateEvent option:

  • 'strict' - Strict being the default, no event overlap is allowed with invalid ranges.
  • 'start-end' - With start-end validation the calendar checks if the start or end of the event coincides with any invalid range. Other overlaps are allowed.

If you're interested in invalids for a given range [including recurring occurrences], you can use the getInvalids function.

Calendar - External drag and drop

Change demo

Events can be created and scheduled by dragging and dropping an external resource onto the calendar. In order for that to work you will need to have two things set up:

  • Enable the calendar to receive external events by setting externalDrop to true.
  • Initialize the external events [containers] as draggable components.

Set up a container as draggable with the mbsc-draggable attribute. Pass a skeleton event definition through the data-drag-data attribute as a stingified json object. This will be added to the event calendar on drop. If omitted, a default event will be created. For a more programmatic approach you might want to use the component initialization where the draggable is initialized in js code and the dragData can be passed as an object.

Learn more from the external drag & drop documentation.

Use the onEventCreate and onEventCreateFailed for triggering a custom logic on drop like showing a toast. The appropriate lifecycle event will be triggered if the drop is successful or fails.

  • JS
  • HTML
  • CSS

Calendar - External d&d presets

Change demo

Use external draggable events to create preset tasks that people can quickly copy and spawn events from. A great example is a car wrapping shop where different jobs need to be set up depending on the type of vehicle.

Print a list of predefined tasks and initialize them as draggable elements. Enable externalDrop for the calendar and set up the predefined event skeletons for the draggable component.

Whenever there is more information to be captured, like a detailed task notes, customer information, the name of the technician... you can trigger a popup with the task form in the onEventCreate lifecycle event. For failed drops [trying to schedule a task during lunch breaks or weekends] the onEventCreateFailed event will be triggered.

  • JS
  • HTML
  • CSS

Calendar - In-header filtering

Change demo

The calendar view doesn't have built in resource listing, however we can easily solve that inside the header using the segmented component. The header of the agenda is a canvas and an opportunity for customization. You can add custom components and enable new interaction in context.

Such an example would be a custom filter block created with the help of a segmented control and placed between the standard UI components, which are:

  • Navigation component -
    . Use the .md-header-filter-controls CSS class for custom overrides.
  • Today button - . Use the .md-header-filter-today CSS class for custom overrides.
  • Previous month button - . Use the .md-header-filter-prev CSS class for custom overrides.
  • Next month button - . Use the .md-header-filter-next CSS class for custom overrides.

For changing the order the controls are laid out, you only need to set up the renderHeader.

Overriding the order for specific themes

For a custom order on a theme to theme basis, you will need to use a little CSS. Flex layout makes reordering easy. It's just a matter of setting the order in CSS. For material use the .mbsc-material, for windows the .mbsc-windows prefix and for iOS it is .mbsc-ios class. Eg.:

.mbsc-material .md-header-filter-prev { order: 1; }
.mbsc-material .md-header-filter-next { order: 2; }
.mbsc-material .md-header-filter-controls { order: 3; }
.mbsc-material .md-header-filter-today { order: 4; }

  • JS
  • HTML
  • CSS

Calendar - Event properties

Change demo

The event data structure for the calendar is straightforward with a couple of base properties that the component understands and uses to render the UI. Besides the base properties you can add any custom property, like location, description ...

  • id - A unique ID for the event. If not specified a unique id will be generated
  • title - Defines the event text. This can be plaintext or HTML
  • tooltip - Defines the text for the tooltip which appears on mouse hover. If not specified, it will show the title and the start/end times of the event.
  • color - Defines the event color
  • start - Sets the start date and time for the event. It can be a js date object, ISO date string or moment.js object. Learn about date formats
  • end - Sets the end date and time for the event. The same formats are supported as for start
  • allDay - Configures the event as a full-day event
  • recurring - Configures the recurring rules for the event. Learn about recurring events
  • resource - Links the event to one or more resources. Expects a list of IDs part of the resources array.
  • editable - Denotes if the event is editable. If set true, the event cannot be dragged, resized or deleted even if globally enabled

Calendar - Supported date formats

Change demo

Understanding how to work with dates inside the event calendar is essential. You can pass to the data, marked, colors and labels in four different formats. The event calendar can work with Javascript date objects, ISO strings and Moment.js objects.

Calendar - Recurrence rules

Change demo

Configure daily, weekly,monthly and yearly recurring events. On top of setting up recurrence, you can exclude specific and recurring days. This is especially useful in cases when a single occurence of an event is deleted or is moved to a different time.

You can pass the recurrence rule in the recurring property of the event as an object or a string in RRULE format. Learn about the event data structure and where to place the recurring rules.

Use the configurator to experiment, build strings and objects that you can grab and use.

Calendar - Loading inline data

Change demo

What is an event calendar without any events in it? To populate it with events all you have to do is pass the event array to the data option.

In a real-world scenario you would probabaly load the events from a remote resource or event better, load them on demand. However the point of this example is to understand how easy it is to add events to the event calendar.

  • JS
  • HTML

Calendar - Events from remote API

Change demo

Calendar - Loading events on demand

Change demo

The event calendar supports remote and local data sources. Besides that, events can be populated on initialization or loaded on demand.

Getting the events in real time as the user navigates improves load performance and always serves the most recent data.

Use the onPageLoading lifecycle event to load the data runtime. You can learn about lifecycle events and places where to drop logic to customize the experience.

  • JS
  • HTML

Calendar - Sync events to google calendar

Change demo

The event calendar comes with third party calendar integration support through the integration plugin. This needs to be added to the download package or installed separately from a dedicated NPM package.

It includes everything you need to authenticate your users, get their Google calendars and provides functions for CRUD operations. It takes care of loading the events and converts them to the required format so that they can be displayed on the Mobiscroll calendar separately or mixed with other calendars and events.

Customizing the interaction, event workflows, whether the events are read-only is up to you. In this live demo, newly created events will land in the primary calendar of the authenticated user.

This example uses the integration plugin to connect to and load events from Google Calendar and it is not available in the trial. Give the live demo a try and see how it can be configured.

  • JS
  • HTML
  • CSS

Calendar - Sync events to outlook calendar

Change demo

The event calendar comes with third party calendar integration support through the integration plugin. This needs to be added to the download package or installed separately from a dedicated NPM package.

It includes everything you need to authenticate your users, get their Outlook calendars and provides functions for CRUD operations. It takes care of loading the events and converts them to the required format so that they can be displayed on the Mobiscroll calendar separately or mixed with other calendars and events.

Customizing the interaction, event workflows, whether the events are read-only is up to you. In this live demo, newly created events will land in the primary calendar of the authenticated user.

This example uses the integration plugin to connect to and load events from Outlook Calendars and it is not available in the trial. Give the live demo a try and see how it can be configured.

  • JS
  • HTML
  • CSS

Calendar - Load events from public google calendar

Change demo

Event data can be loaded from remote sources, like public google calendars. Through the integration plugin you can easily show events that are available in a public calendar. The integration plugin needs to be added to the download package or installed separately from a dedicated NPM package.

You will just need the CALENDAR_ID and an apiKey from google and you should be ready to roll.

Public calendars are read-only. If you are interested in syncing private google calendars with read/write/delete access, check out this example.

This example uses the integration plugin to connect to and load events from Google Calendar and it is not available in the trial. Give the live demo a try and see how it can be configured.

  • JS
  • HTML
  • CSS

Calendar - Add/edit/delete events

Change demo

Create new events

Drag to create and click to create is enabled. Events can be created by dragging or with double clicks. As soon as the initial position is confirmed, a temporary event is created and a custom edit dialog is shown for refinement. On cancel the temporary event will be removed and on confirmation the event will stay in the calendar.

Edit existing events

Drag to resize and drag to move is enabled. Events can be reordered and resized. In addtion to that, clicking on the event will open a custom dialog that enables editing the various properties.

Delete events

Delete can be implemented inside the edit dialog with a button. It's just a matter of removing it from the data object. If a dialog is not shown on click, focused events can be deleted with the backspace and delete keys.

  • JS
  • HTML
  • CSS

Calendar - Recurring event editor

Change demo

As seen in the previous example, an add/edit from can be created with custom and base event fields. While the CRUD example features delete with undo, this example shows off how to build a fully customizable recurrence editor right in the add/edit screen.

Above some common presets, like Daily, Weekly on X day, Monthly on Xth, Annually on the same day, Every Weekday a fully custom recurrence editor is implemented.

Copy & paste or delve into the code and understand how to generate recurrence objects or RRULES as seen in this live rule builder.

  • JS
  • HTML
  • CSS

Calendar - Disable past event creation

Change demo

Sometimes we don't want users to be able to create events in the past or to alter past events. This might be role based in some cases or applied in general to the calendar.

To disable past event creation and manipulation, a couple of things need to be handled:

  • Invalidate dates that are before today - this takes care of validating event drop and event creation on past dates
  • Mark past events as fixed - to do this, set the editable property of the event object to false for the events that should remain fixed
  • Handle past occurrences of recurring events - recurring events are loaded as a single event and the occurrences are generated by the event calendar. Moving the past occurrences need to be handled in the onEventUpdate and onEventCreate lifecycle events
  • Give feedback to the user - optionally, a toast can be displayed to give feedback to the user why an event cannot be dropped, moved and created in the past. For this we can use the onEventCreateFailed and onEventUpdateFailed lifecycle events

  • JS
  • HTML
  • CSS

Calendar - Multiple select & bulk operations

Change demo

Multiple event selection can be turned on with the selectMultipleEvents option. Selecting multiple events can be done through user interaction with CTRL/SHIFT/CMD + click or programmatically eg. click of a button or 'select all' checkbox.

Bulk operations like delete, update can be applied the selected events. Things like deleting with the backspace or delete buttons work out of the box but custom actions can be also applied. The selection can be easily retreived and updated with the getSelectedEvents and setSelectedEvents method.

Custom actions can be performed with external buttons or with context menu activated on right-click.

  • JS
  • HTML
  • CSS

Calendar - Move events between calendars

Change demo

While copy & pasting one or more events is useful, sometimes being able to move events between two separate calendars can improve productivity. How the calendars are laid out depends on the application, but the basic idea is that you will need to be able to tell where the events from the clipboard will be pasted.

In this example this is implemented by tracking the active instance, which is determined by the active tab of the segmented control. With this out of the way, CTRL/CMD+C/X/Z/V handle the copy, cut, undo and paste actions.

  • JS
  • HTML
  • CSS

Calendar - Theming capabilities

Change demo

The look and feel of the event calendar can be deeply customized. There are four levels of customization:

  • Base themes: Choose between iOS, Material and Windows.
  • Light or dark: Every theme has a light and dark variant. Setting the themeVariant to 'auto' will switch based on system settings.
  • Custom themes: Use the theme builder to customize the colors and make it match your brand.
  • Custom CSS: If you need further customization, the sky is the limit with CSS overrides.

You can also see how every example looks by changing the theme from the header.

Calendar - Localization

Change demo

The components are fully localized. In case of the event calendar this covers date and time format, button copy, rtl and more. You can see how each example shows up by clicking on the small flag icon or checking the examples below.

  • JS
  • HTML
  • CSS

Calendar - Calendar systems

Change demo

The event calendar supports multiple calendar systems. You can control it with the calendarSystem setting, and it supports the following options:

  • Gregorian - it is included by default
  • Jalali - it is the default system of the Persian calendar and is inlcuded within the Farsi language pack
  • Hijri - it is included in the Arabic language pack

Calendar - Lifecycle events

Change demo

The event calendar ships with different hooks for deep customization. Events are triggered through the lifecycle of the component where you can tie in custom functionality and code.

While users interact with the UI events like onEventClick, onInit, onSelectedDateChange ... will be triggered.

Looking for something you didn't see or have a sales question?
Ask us about it, we're here to help.

How do I create a calendar event in HTML?

Read more in the resource calendar tutorials for JavaScript, Angular, React and Vue..
Step 1: Event Calendar JavaScript Library. Include daypilot-all. ... .
Step 2: Event Calendar Placeholder. ... .
Step 3: Initialize the Scheduler. ... .
Step 4: Load Data. ... .
Step 5: Event Moving. ... .
Step 6: Event Editing. ... .
Step 7: Apply the CSS Theme..

How do I create a dynamic event calendar in HTML?

How to use it:.
To use the component, make sure you have jQuery library and Bootstrap 4 framework loaded in the document. ... .
Load the latest moment. ... .
Load the calendar's stylesheet in the document. ... .
Create a DIV container to hold the event calendar. ... .
Import the loading spinner module if needed..

How do you write a calendar in JavaScript?

Write a function createCalendar[elem, year, month] . The call should create a calendar for the given year/month and put it inside elem . The calendar should be a table, where a week is , and a day is . The table top should be with weekday names: the first day should be Monday, and so on till Sunday.

How do I add events to my Evo calendar?

How to use it:.
Add jQuery evo-calendar plugin's JavaScript and CSS files into the HTML document. ... .
Create a container to hold the event calendar. ... .
Create events in an array of objects containing dates, event names and event types [event, holiday, birthday]. ... .
Call the function to generate an event calendar on the page..

Chủ Đề