Skip to main content Skip to footer

How to Build a JavaScript Calendar Component in Your Web Application

Quick Start Guide
What You Will Need
  • NPM
  • NodeJS
  • VisualStudio Code
  • Wijmo
Controls Referenced

JavaScript FlexScheduler

Tutorial Concept Implement a JavaScript Calendar with Wijmo’s FlexScheduler, including event data binding, resource scheduling, conflict detection, custom layouts, and interactive event management.

Modern business applications often require more than a simple calendar; teams may need to schedule employee meetings, reserve rooms and equipment, manage appointments, or organize other time-based data while giving users a simple way to view and update that information. Wijmo's FlexScheduler control is designed for these scenarios, providing a flexible JavaScript calendar component that combines calendar views, event management, resource scheduling, and built-in user interactions in a single control.

FlexScheduler can bind directly to your application data and display scheduled events across several built-in layouts. It also supports common scheduling interactions, such as creating, editing, deleting, moving, and resizing events, as well as more advanced features, including resource grouping, conflict detection, custom event templates, configurable context menus, and time zone support.

In this article, we'll walk through adding a FlexScheduler control to a JavaScript application, binding it to event data, and configuring it for a practical scheduling experience. From there, we'll explore some of its key features and customization options so you can see how FlexScheduler can be adapted to fit scheduling requirements ranging from straightforward calendars to more complex, resource-driven business applications. By the end, we will have covered:

Ready to get started? Download Wijmo Today!

Adding the FlexScheduler Control to the Application

To get started, we'll need to add the Wijmo library to our application. This can be done by running the following command:

npm install @mescius/wijmo.all

Once NPM completes the installation, we'll need to import the required files to use Wijmo's FlexScheduler control. Inside the main.js file, we'll add the imports for Wijmo's required CSS file, as well as the FlexScheduler component:

import '@mescius/wijmo.styles/wijmo.css';
import * as wjCore from '@mescius/wijmo';
import * as wjScheduler from '@mescius/wijmo.scheduler';

Now, we'll also import a third file and assign it to the value wjCore; this import is the core Wijmo module and is what allows us to use the CollectionView, Wijmo's data management control. This will be used to handle the underlying data that will go in the FlexScheduler control and to track any changes made to that data.

With the imports complete, we can move on to setting up the FlexScheduler control. To start, we'll set up some mock data to show what the data can look like:

const events = new wjCore.CollectionView([
  { title: 'Engineering Standup', beginsAt: new Date(2026, 9, 30, 9), endsAt: new Date(2026, 9, 30, 9, 30) },
  { title: 'Production Meeting', beginsAt: new Date(2026, 9, 30, 10), endsAt: new Date(2026, 9, 30, 11) },
  { title: 'Knowledge Transfer', beginsAt: new Date(2026, 9, 30, 12), endsAt: new Date(2026, 9, 30, 13, 30) },
  { title: 'Marketing Initiative Kickoff', beginsAt: new Date(2026, 9, 30, 15), endsAt: new Date(2026, 9, 30, 16) },
]);

As you can see, we're using the CollectionView mentioned to hold the data we're loading into the JavaScript calendar. Each object in the array is given three properties:

  • title: the title of the event
  • beginsAt: when the event starts
  • endsAt: when the event ends

You may use different property names when referencing event names and start/end times; that's okay. The FlexScheduler component allows you to declare which properties in your data you want to bind the FlexScheduler to, so we won't run into any issues.

Now, we can move on to setting up the FlexScheduler:

const scheduler = new wjScheduler.FlexScheduler('#scheduler', {
  itemsSource: events,
  eventFields: { subject: 'title', start: 'beginsAt', end: 'endsAt' },
  displayDate: new Date(2026, 9, 30),
});

When we declare the FlexScheduler, we're passing an argument, #scheduler, to the control. This argument is the ID of the element to which we want to bind the control. So, we'll be sure to add this element to our markup:

<div class="container">
  <div id="scheduler"></div>
</div>

Regarding the rest of the FlexScheduler setup, the itemsSource is where the control looks for the data it's going to load, so we'll pass the events CollectionView we set up as its itemsSource. Then, we use the eventFields property to tell the control which property values in the data we want to bind to. Finally, we give the control a date to open up to when the control loads into the browser.

With everything completed, we can run the application, and you should see the FlexScheduler displaying in your browser, along with the events that were given to the control:

JavaScript Calendar

Out of the box, you're able to change the different views of the calendar, as well as navigate to different days/weeks/months of the year, with the toolbar at the top of the FlexScheduler:

JavaScript Calendar

Configuring Resources

Wijmo's JavaScript Calendar component, FlexScheduler, also allows you to configure custom resources for display within the calendar. Perhaps when scheduling events, you'd like to track which room the meeting is scheduled for, which team is in the meeting, or which equipment is needed; thanks to FlexScheduler, you can both separate these resources and add signifiers to make them stand out from one another.

Building on what we've done in the FlexScheduler setup, we'll add a set of resources, assign them to our existing events, and then bind them to the FlexScheduler. To get started, we'll set up the layout of our resource (in this case, office rooms):

const rooms = [
  { id: 'room-a', text: 'Conference Room A', background: '#628dde', color: '#000000' },
  { id: 'room-b', text: 'Conference Room B', background: '#bede40', color: '#000000' },
  { id: 'room-c', text: 'Fiji Room', background: '#16d9ab', color: '#000000' },
];

We've set up three rooms here: Conference Room A, Conference Room B, and Fiji Room. We've given each of them an ID to associate them with events, and we've also assigned a background and foreground color to each room. The foreground color will be used to style the text, while the background color will color the event block itself.

Now, we'll go and update the events array to include associated rooms:

const events = new wjCore.CollectionView([
  { title: 'Engineering Standup', beginsAt: new Date(2026, 9, 30, 9), endsAt: new Date(2026, 9, 30, 9, 30), roomId: 'room-c' },
  { title: 'Production Meeting', beginsAt: new Date(2026, 9, 30, 10), endsAt: new Date(2026, 9, 30, 11), roomId: 'room-a' },
  { title: 'Knowledge Transfer', beginsAt: new Date(2026, 9, 30, 12), endsAt: new Date(2026, 9, 30, 13, 30), roomId: 'room-a' },
  { title: 'Marketing Initiative Kickoff', beginsAt: new Date(2026, 9, 30, 15), endsAt: new Date(2026, 9, 30, 16), roomId: 'room-b' },
]);

Then we need to set up the resource object to pass to the FlexScheduler. This resource object will bind properties from our rooms array to existing property values of the scheduler component:

const resource = [{
  fieldExpr: 'roomId',
  label: 'Room',
  dataSource: rooms,
  valueExpr: 'id',
  displayExpr: 'text',
  backgroundColorExpr: 'background',
  foreColorExpr: 'color'
}];

Finally, we'll add this resource object to the FlexScheduler component:

const scheduler = new wjScheduler.FlexScheduler('#scheduler', {
  itemsSource: events,
  resources: resource,
  eventFields: { subject: 'title', start: 'beginsAt', end: 'endsAt' },
  displayDate: new Date(2026, 9, 30),
});

Now, when we save the changes and navigate back to the browser, we'll see the updated events in the FlexScheduler:

JavaScript Calendar Events

As you can see, each event is now properly colored and includes the room where it is taking place in the display.

Adding, Editing, and Deleting Events

Now, most JavaScript calendar controls aren't designed to be static elements for displaying events; you want your users to be able to add new events, make changes when needed, and even delete events that are no longer required. Thankfully, this is possible with the FlexScheduler control, and no additional input is needed from the developers; this functionality comes right out of the box.

To add a new event, a user needs to either double-click on an empty area of the calendar or right-click to bring up the calendar's context menu and click Add, which will bring up the Add Event menu:

JavaScript Calendar Add Event

From here, users can give the event a title, provide start and end dates, and add a description if necessary.

For editing events, users can either double-click on an existing event or right-click on the event to bring up the context menu and select the Edit option:

JavaScript Calendar Edit Event

Finally, to delete an event, users can either click the Delete button in the Edit Event window or right-click the event and select the Delete option from the context menu.

Now, these aren't the only ways that users can edit events. The FlexScheduler component also allows users to drag and drop events into different day/time slots and change event duration by resizing the event itself.

JavaScript Calendar Drag and Drop

This feature is available natively and out of the box. If you'd like to disable this feature for your users, the allowDragEvent and allowResizingEvent are made available to developers:

const scheduler = new wjScheduler.FlexScheduler('#scheduler', {
  itemsSource,
  allowDragEvent: false,
  allowResizeEvent: false,
});

Handling Event Conflicts

By default, Wijmo's FlexScheduler control allows you to schedule meetings with conflicting times; these meetings may not take place in the same location or require the same individuals, so this makes sense. However, FlexScheduler also has an event called conflictChecked that lets you implement your own conflict-checking logic to meet your product requirements.

We can set up our own conflict handling by using the addHandler method with the conflictChecked event:

scheduler.conflictChecked.addHandler((_sender, args) => {
  const conflicts = args.result?.conflicts ?? [];
  if(conflicts.length > 0) {
    alert("Conflicting Event: " + conflicts[0].conflictingItems[0].title);
    args.cancel = true;
  }
})

Now, if we go back to the browser and move an event to cause a conflict, we'll see the following in the browser:

JavaScript Calendar Event Conflict

The way we've set up our conflict detection will undo the rescheduling of the event because we've set the args.cancel property to true; this will cause the change to be undone. If you'd like to allow the conflict, you can exclude that line of code, and it will be allowed.

Now, if you're using resources to indicate the room or location where the event takes place, Wijmo's FlexScheduler will take that into account. When using multiple resources, two events conflict only when every resource field they both set has the same value. For a better understanding, see the table below:

Event A Event B Time Overlap Conflict
09:00-10:00, Room A 10:00-11:00, Room A No, time ranges do not conflict
09:00-10:00, Room A 09:30-10:30, Room A Yes, time ranges conflict
09:00-10:00, Room A 09:30-10:30, Room B No, resource values differ

This conflict detection can be expanded to allow you to check for teams, individuals, or a combination of all.

Configuring and Creating Advanced Layouts

At the top of the article, we went over the different built-in views available with the FlexScheduler. The control lets you determine which of these views are available to your users and build and define your own advanced layouts. Building on what we've already done, we'll configure the layout selection to limit the available views to what we want, and then add our own advanced layout that lets us break out each calendar day across the available office rooms.

To start, let's limit the views users can select from. To do so, we can use FlexScheduler's toolbarViewItems array to define what views we want to include, as well as what we call them in the UI:

scheduler.toolbarViewItems = [
  { name: 'Day', key: wjScheduler.SchedulerBuiltInViewItem.Day },
  { name: 'Week', key: wjScheduler.SchedulerBuiltInViewItem.WorkWeek },
  { name: 'Month', key: wjScheduler.SchedulerBuiltInViewItem.Month },
]

This property accepts an array of objects, with the properties name and key, where name is what is displayed in the UI, and key is the actual view that will be displayed. Now, if we save and run the application, we'll see the following:

JavaScript Calendar Advanced Layouts

As you can see, it now displays only the items we defined for our toolbar: Day, Week, and Month.

Now, we're going to create our own custom view layout for the scheduled events. To do so, we'll create a custom SchedulerDefinition that places ordered time and resource bindings on the row and column axes.

Binding Type Defines Typical Values Required Properties Optional Properties
Time Date or time slots Hour, Day, DayOfWeek, DayOfMonth type, unit visible callback
Resource Groups from scheduler.resources roomId, teamId type, fieldExpr None

The binding order determines which binding becomes the outer group and which becomes the inner. The fieldExpr of a resource binding must match a configured resource descriptor:

const definition = {
  key: 'weekByRoom',
  rows: {
    bindings: [{
      type: wjScheduler.SchedulerAxisBindingType.Time,
      unit: wjScheduler.SchedulerTimeUnit.Hour
    }],
  },
  columns: {
    bindings: [
      { type: wjScheduler.SchedulerAxisBindingType.Time, unit: wjScheduler.SchedulerTimeUnit.DayOfWeek },
      { type: wjScheduler.SchedulerAxisBindingType.Resource, fieldExpr: 'roomId' }
    ]
  }
}

In this definition, we've created our new view, called weekByRoom, and we're defining the rows and columns. The rows binding defines how the row values will be displayed; in this case, we're defining them as time values, broken down into hours.

Then, for the columns binding, we first bind the day of the week, and underneath that we bind the roomId resource as its sub-column grouping.

Finally, we pass this definition along to the FlexScheduler component:

const scheduler = new wjScheduler.FlexScheduler('#scheduler', {
  itemsSource: events,
  resources: resource,
  definition: definition,
  eventFields: { subject: 'title', start: 'beginsAt', end: 'endsAt' },
  displayDate: new Date(2026, 9, 30),
});

Now, when we save the changes and navigate back to the browser, we'll see the new view that we've created:

JavaScript Calendar Advanced Layouts

As you can see, the columns are broken up into day groupings, with room groupings underneath each day, and each event displays in its associated room column.

Custom Event Displays and Templates

The last topic that we'll cover in this article is creating custom event displays and templates. The FlexScheduler control allows you to customize event displays beyond just the color of the text and background; you can add your own custom HTML elements to the event displays to provide additional context to your users, such as who is going to attend, what topics will be discussed, or the progress of the task being worked on.

For this article, we'll keep things simple. To get started, we're going to add some escape HTML characters, and then we'll update the definition that we created previously to include the updated item template:

const escapeHtml = (value) => String(value ?? '')
  .replaceAll('&', '&amp;')
  .replaceAll('<', '&lt;')
  .replaceAll('>', '&gt;')
  .replaceAll('"', '&quot;')
  .replaceAll("'", '&#39;');

The FlexScheduler assigns the returned string to the event element's innerHTML, so escape every value that comes from users or an external service. Unescaped markup can inject HTML into the page, which is an XSS risk. Return only the inner content of the event. Scheduler creates and owns the surrounding element and its interaction state, so do not return a wrapper element.

const definition = {
  ...
  itemTemplate: context => `
    <div class="appointment-title"><strong>${escapeHtml(context.item.title)}</strong></div>
    <div class="appointment-location">${escapeHtml(context.resources[0].text)}</div>
    <div class="appointment-time">${escapeHtml(formatTime(context.item))}</div>
  `
}

What the update in the definition does is tell the FlexScheduler control that, when loading the definition, it should use the HTML we've defined in the itemTemplate property to build out the event items. In this itemTemplate, we're creating three div elements, assigning each a class, and using them to display each event's content. As you can see, we're also using the escapeHTML that we set up to prevent XSS.

In the appointment-time div, we're also calling a function, called formatTime(), which we'll use to format datetime objects for display properly:

function formatTime(item) {
  const options = { hour: 'numeric', minute: '2-digit' };
  return `${item.beginsAt.toLocaleTimeString(undefined, options)}-${item.endsAt.toLocaleTimeString(undefined, options)}`;
}

Notice that these elements also have classes associated with them; we can use these in our CSS file to add additional styling to our item templates. For this sample, we've kept it pretty simple and just provided some basic text stylings:

.appointment-location {
  color: white;
  font-style: italic;
}

.appointment-time {
  color: white;
  font-weight: normal;
}

Now, when we save the changes made and navigate back to the browser, we'll see the itemTemplates in action:

JavaScript Calendar itemTemplates

As you can see, we've added a bold effect to the meeting titles and given the meeting locations a white, italicized color.

Now, you're not limited to just editing the text and style of an event. If you're familiar with custom cells in Wijmo's FlexGrid, you know that the sky is the limit. You can include items such as custom elements, interactable controls, and images and icons, making Wijmo's FlexScheduler's itemTemplate a powerful feature within the JavaScript calendar control.

Ready to check it out? Download Wijmo Today!

Conclusion

With that, we've come to the end of the article. We hope this has given you a glimpse into Wijmo's newest control, its JavaScript calendar, FlexScheduler, and what you're capable of building with it.

To get started with Wijmo, you can download the library from our website or install it via NPM. For more information on Wijmo's controls, check out our demos and documentation page. If you'd like to learn more, feel free to schedule a demo with our team.

Tags:

comments powered by Disqus