Click here to Skip to main content
13,836,649 members
Click here to Skip to main content
Add your own
alternative version


317 bookmarked
Posted 24 Feb 2014
Licenced Apache

HTML5 Event Calendar/Scheduler

, 18 Jun 2018
Rate this:
Please Sign up or sign in to vote.
Weekly HTML5 event calendar with CSS themes, drag and drop support, date navigator. PHP/AJAX and ASP.NET MVC backends.

HTML5 Event Calendar/Scheduler (Open-Source)

In this article we will build a simple HTML5 event calendar web application. The client-side (HTML5/JavaScript) part is universal. We will use sample PHP and ASP.NET MVC backends.


  • Weekly HTML5 event calendar/scheduler
  • Changing the calendar using a date navigator (on the left side)
  • Drag and drop event creating, moving and resizing
  • Changing the look in a single click using a CSS theme
  • PHP AJAX backend
  • ASP.NET MVC AJAX backend

We will use DayPilot Lite for JavaScript [] to build the event calendar. DayPilot Lite for JavaScript is open-source - available under Apache License 2.0.

Scheduler CSS Themes

DayPilot Lite for JavaScript comes with several pre-built CSS themes.

You can create your own theme using the online CSS theme designer [].

Default CSS Theme

HTML5 Event Calendar - Default CSS Theme

Green CSS Theme

HTML5 Event Calendar - Green CSS Theme

Google-Like CSS Theme

HTML5 Event Calendar - Google-Like CSS Theme

Traditional CSS Theme

HTML5 Scheduler - Traditional CSS Theme

Transparent CSS Theme

HTML5 Scheduler - Transparent CSS Theme

White CSS Theme

HTML5 Scheduler - White CSS Theme

Step 1: Event Calendar JavaScript Library

Include daypilot-all.min.js. No other dependecies are required for the basic look (the default CSS theme is embedded).

<script src="js/daypilot/daypilot-all.min.js" type="text/javascript"></script> 

Step 2: Event Calendar Placeholder

Add a placeholder <div> to the HTML5 page:

<div id="dp"></div> 

Step 3: Initialize the Scheduler

Initialize the scheduler using Daypilot.Calendar class:

<script type="text/javascript">
  var dp = new DayPilot.Calendar("dp");
  dp.viewType = "Week";

These simple steps will render an empty scheduler:

HTML5 Event Calendar (Empty)

Step 4: Load Data

We will load the data to the event calendar using a simple AJAX call:

function loadEvents() {
  $.post("backend_events.php", // use "backend/events" for ASP.NET MVC
    start: dp.visibleStart().toString(),
    end: dp.visibleEnd().toString()
  function(data) { = data;

Since version 2018.2.232 you can also use a built-in shortcut method to load events:

function loadEvents() {"backend_events.php"); // use "backend/events" for ASP.NET MVC

We will detect the currently-visible date range using visibleStart() and visibleEnd() methods and send it to backend_events.php as parameters.

The backend_event.php endpoint returns the calendar event data in the following format:

    "text":"Calendar Event 1",
    "text":"Calendar Event 2",
    "text":"Calendar Event 3",

PHP backend (backend_events.php):

require_once '_db.php';
$stmt = $db->prepare('SELECT * FROM events WHERE NOT ((end <= :start) OR (start >= :end))');

$stmt->bindParam(':start', $_GET['start']);
$stmt->bindParam(':end', $_GET['end']);

$result = $stmt->fetchAll();

class Event {}
$events = array();

foreach($result as $row) {
  $e = new Event();
  $e->id = $row['id'];
  $e->text = $row['name'];
  $e->start = $row['start'];
  $e->end = $row['end'];
  $events[] = $e;

echo json_encode($events);


ASP.NET MVC backend (BackendController.cs)

public ActionResult Events(DateTime? start, DateTime? end)

  var events = from ev in db.Events.AsEnumerable() where !(ev.end <= start || ev.start >= end) select ev;

  var result = events
  .Select(e => new JsonEvent() { 
      start = e.start.ToString("s"),
      end = e.end.ToString("s"),
      text =,
      id =

  return new JsonResult { Data = result, JsonRequestBehavior = JsonRequestBehavior.AllowGet };

Read more about loading the calendar event data [].

Step 5: Event Moving

HTML5 Event Calendar - Drag and Drop Moving

The drag and drop user actions (selecting a time range, event moving, event resizing) are enabled by default in the scheduler.

We just need to add custom handler to submit the changes to the server side using an AJAX call.

JavaScript event handler

dp.onEventMoved = function (args) {
  $.post("backend_move.php",   // use "backend/move" for ASP.NET MVC
        newStart: args.newStart.toString(),
        newEnd: args.newEnd.toString()
    function() {

PHP backend (backend_move.php)

require_once '_db.php';

$insert = "UPDATE events SET start = :start, end = :end WHERE id = :id";

$stmt = $db->prepare($insert);

$stmt->bindParam(':start', $_POST['newStart']);
$stmt->bindParam(':end', $_POST['newEnd']);
$stmt->bindParam(':id', $_POST['id']);


class Result {}

$response = new Result();
$response->result = 'OK';
$response->message = 'Update successful';

echo json_encode($response);


ASP.NET MVC backend (BackendController.cs)

public ActionResult Move(int id, string newStart, string newEnd)
  var toBeResized = (from ev in db.Events where == id select ev).First();
  toBeResized.start = Convert.ToDateTime(newStart);
  toBeResized.end = Convert.ToDateTime(newEnd);

  return new JsonResult { Data = new Dictionary<string, object> { { "id", } } };

Read more about drag and drop event moving [].

Step 6: Apply the CSS Theme

HTML5 Event Calendar - CSS Theme

If you want to use a custom CSS theme you need to include the stylesheet:

<link type="text/css" rel="stylesheet" href="themes/calendar_transparent.css" /> 

And set the theme property during initialization:

<script type="text/javascript">
  var dp = new DayPilot.Calendar("dp");
  dp.viewType = "Week";
  dp.theme = "calendar_transparent";

You can choose one of the included CSS themes or you can create your own using the online CSS theme designer.

Monthly Event Calendar

HTML5 Monthly Event Calendar

DayPilot also includes a monthly event calendar view. The API of the monthly view control uses the same design as the daily/weekly calendar:

<div id="dp"></div>

<script type="text/javascript">
  var dp = new DayPilot.Month("dp");
  dp.startDate = "2016-01-01";

Event Calendar Localization

HTML5 Event Calendar Localization

You can switch the event calendar locale easily using .locale property:

<script type="text/javascript">
  var dp = new DayPilot.Calendar("dp");
  dp.locale = "de-de";

The calendar includes built-in support for the following locales:

  • ca-es
  • cs-cz
  • da-dk
  • de-at
  • de-ch
  • de-de
  • de-lu
  • en-au
  • en-ca
  • en-gb
  • en-us
  • es-es
  • es-mx
  • eu-es
  • fi-fi
  • fr-be
  • fr-ch
  • fr-fr
  • fr-lu
  • gl-es
  • it-it
  • it-ch
  • ja-jp
  • nb-no
  • nl-nl
  • nl-be
  • nn-no
  • pt-br
  • pl-pl
  • pt-pt
  • ru-ru
  • sk-sk
  • sv-se
  • zh-cn

You can also create and register your own locale:

  new DayPilot.Locale('en-us', 
    'timePattern':'h:mm tt',
    'dateTimePattern':'M/d/yyyy h:mm tt',

Changing the Scheduler Date

You can use the DayPilot.Navigator control (on the left side in the screenshot above) to change the scheduler dates (the visible week):

<div id="nav"></div>

<script type="text/javascript">
  var nav = new DayPilot.Navigator("nav");
  nav.showMonths = 3;
  nav.skipMonths = 3;
  nav.selectMode = "week";
  nav.onTimeRangeSelected = function(args) {
      dp.startDate =;

Duration Bar

HTML5 event calendar with duration bar support

Version 1.1 of the DayPilot Lite HTML5 event calendar supports a duration bar (an indicator of real calendar event duration on the left side of the event). It is enabled by default and you can style it using the CSS theme.

Event Customization (HTML, CSS)

HTML5 Event Calendar Customization

Since version 1.3 SP3, DayPilot Lite supports event customization using onBeforeEventRender event handler:

<div id="dp"></div>

<script type="text/javascript">

    var dp = new DayPilot.Calendar("dp");

    // view
    dp.startDate = "2016-06-06";
    dp.viewType = "Week";
    dp.durationBarVisible = false; = [
            "start": "2016-06-07T10:00:00",
            "end": "2016-06-07T13:00:00",
            "id": "29b7a553-d44f-8f2c-11e1-a7d5f62eb123",
            "text": "Event 3",
            "backColor": "#B6D7A8",
            "borderColor": "#6AA84F"
            "start": "2016-06-07T14:00:00",
            "end": "2016-06-07T17:00:00",
            "id": "ff968cfb-eba1-8dc1-7396-7f0d4f465c8a",
            "text": "Event 4",
            "backColor": "#EA9999",
            "borderColor": "#CC0000",
            "tags": {
                "type": "important"

    dp.onBeforeEventRender = function(args) {
        if ( && === "important"){
   = "<b>Important Event</b><br>" +;
   = "#fff";
   = "#E06666";



You can use it to customize the following properties:

  • backColor
  • barBackColor
  • barColor
  • barHidden
  • borderColor
  • cssClass
  • fontColor
  • html
  • toolTip


Monthly Calendar Event Customization

HTML5 Monthly Event Calendar Customization

Event customization support was added to the monthly calendar control in DayPilot Lite for JavaScript 1.3 SP4.

DayPilot Month supports customization of the following event properties:

  • backColor
  • borderColor
  • cssClass
  • fontColor
  • html
  • toolTip



<div id="dp"></div>

<script type="text/javascript">
    var dp = new DayPilot.Month("dp");

    // ... = [
            "start": "2013-03-03T00:00:00",
            "end": "2013-03-03T12:00:00",
            "id": "5a8376d2-8e3d-9739-d5d9-c1fba6ec02f9",
            "text": "Event 3"
            "start": "2013-02-25T00:00:00",
            "end": "2013-02-27T12:00:00",
            "id": "1fa34626-113a-ccb7-6a38-308e6cbe571e",
            "text": "Event 4",
            "tags": {
                "type": "important"
        // ...

    dp.onBeforeEventRender = function(args) {
        var type = &&;
        switch (type) {
            case "important":
       = "#fff";
       = "#E06666";
       = "#E06666";
            // ...



AngularJS Plugin

Angular JS Event Calendar/Scheduler

Since version 1.2, DayPilot Lite includes an AngularJS Event Calendar plugin that allows using the event calendar in AngularJS. The calendar can be initialized using a special directive (<daypilot-calendar> element). It supports AngularJS two-way automatic data binding.

Quick Example:

<script src="scripts/angular.min.js" type="text/javascript"></script>
<script src="scripts/daypilot-all.min.js" type="text/javascript"></script>

<div ng-app="main" ng-controller="CalendarCtrl" >
  <daypilot-calendar id="dp" config="config" ></daypilot-calendar>

<script type="text/javascript">
  var app = angular.module('main', ['daypilot']).controller('CalendarCtrl', function($scope) {
      // ...
      $scope.config = {
          startDate: "2016-09-01",
          viewType: "Week"

See also AngularJS Event Calendar Tutorial [].

AngularJS "controller as" Syntax

DayPilot Lite for JavaScript 1.3 SP2 and later versions support AngularJS "controller as" syntax:

<script src="scripts/angular.min.js" type="text/javascript"></script>
<script src="scripts/daypilot-all.min.js" type="text/javascript"></script>

<div ng-app="main" ng-controller="CalendarCtrl as ctrl" >
  <daypilot-calendar id="dp" config="ctrl.config" events="" publish-as="ctrl.calendar"></daypilot-calendar>

<script type="text/javascript">
  var app = angular.module('main', ['daypilot']).controller('CalendarCtrl', function() {
      // ...
      var ctrl = this;

      ctrl.config = {
          startDate: "2016-09-01",
          viewType: "Week"
      }; = [
              start: new DayPilot.Date("2016-09-01T10:00:00"),
              end: new DayPilot.Date("2016-09-01T14:00:00"),
              id: 10001,
              text: "First Event"

See also the "controller as" event calendar demo [].

jQuery Plugin

DayPilot includes a jQuery event calendar plugin that allows initialization of the calendar using jQuery API.

Quick example:

<script src="scripts/jquery.min.js" type="text/javascript"></script>
<script src="scripts/daypilot-all.min.js" type="text/javascript"></script>

<div id="dp"></div>
<script type="text/javascript">
    var dp = $("dp").daypilotCalendar({
      startDate: new DayPilot.Date("2013-03-25").firstDayOfMonth(),
      viewType: "Week"

See Also



This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0


About the Author

Dan Letecky
Czech Republic Czech Republic

You may also be interested in...

Comments and Discussions

QuestionRecurring events? RRULE? Pin
Member 1350434319-Jun-18 13:06
memberMember 1350434319-Jun-18 13:06 
QuestionMessage Closed Pin
28-Feb-18 0:10
memberroyka28-Feb-18 0:10 
QuestionIs it free and can use commercial product Pin
Mou_kol27-Feb-18 21:54
memberMou_kol27-Feb-18 21:54 
AnswerRe: Is it free and can use commercial product Pin
Dan Letecky18-Jun-18 5:45
memberDan Letecky18-Jun-18 5:45 
QuestionOverlapping Events? Pin
Connie DeCinko15-Dec-16 5:28
memberConnie DeCinko15-Dec-16 5:28 
QuestionOverlapping Events? Pin
Connie DeCinko15-Dec-16 5:28
memberConnie DeCinko15-Dec-16 5:28 
Questioncanendar does not show if I change index.cshtml Pin
petercli17-Sep-16 5:53
memberpetercli17-Sep-16 5:53 
GeneralCalendar/Scheduler event coding system Pin
Member 1270290925-Aug-16 1:25
memberMember 1270290925-Aug-16 1:25 
QuestionJuste thanks for sharing Pin
JulienduWeb9-Jun-16 4:12
memberJulienduWeb9-Jun-16 4:12 
AnswerRe: Juste thanks for sharing Pin
Dan Letecky9-Jun-16 22:17
memberDan Letecky9-Jun-16 22:17 
QuestionRead only mode available Pin
Member 412512527-Apr-16 21:22
memberMember 412512527-Apr-16 21:22 
AnswerRe: Read only mode available Pin
Dan Letecky29-Apr-16 5:13
memberDan Letecky29-Apr-16 5:13 
GeneralMy vote of 5 Pin
csharpbd26-Apr-16 11:39
professionalcsharpbd26-Apr-16 11:39 
GeneralRe: My vote of 5 Pin
Dan Letecky26-Apr-16 11:46
memberDan Letecky26-Apr-16 11:46 
GeneralMy vote of 5 Pin
JH645-Nov-15 3:21
memberJH645-Nov-15 3:21 
GeneralRe: My vote of 5 Pin
Dan Letecky5-Nov-15 3:31
memberDan Letecky5-Nov-15 3:31 
QuestionMy Vote of 5 Pin
Robert Marck4-Nov-15 5:08
memberRobert Marck4-Nov-15 5:08 
AnswerRe: My Vote of 5 Pin
Dan Letecky4-Nov-15 10:27
memberDan Letecky4-Nov-15 10:27 
QuestionLocalization and header format Pin
Member 1047687316-Oct-15 8:28
memberMember 1047687316-Oct-15 8:28 
AnswerRe: Localization and header format Pin
Dan Letecky2-Nov-15 5:56
memberDan Letecky2-Nov-15 5:56 
QuestionMy vote of 5 Pin
Gloold4-Oct-15 23:12
memberGloold4-Oct-15 23:12 
AnswerRe: My vote of 5 Pin
Dan Letecky2-Nov-15 5:59
memberDan Letecky2-Nov-15 5:59 
QuestionDayPilot Calendar cannot Update clientState If i Navigate... Pin
Victor Ebe21-May-15 7:12
memberVictor Ebe21-May-15 7:12 
GeneralPHP Worked great! - 5 stars Pin
Jan Zumwalt4-Apr-15 8:13
memberJan Zumwalt4-Apr-15 8:13 
GeneralRe: PHP Worked great! - 5 stars Pin
Dan Letecky6-Apr-15 4:27
memberDan Letecky6-Apr-15 4:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web06 | 2.8.190114.1 | Last Updated 18 Jun 2018
Article Copyright 2014 by Dan Letecky
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid