Initialization

To use dhtmlxCalendar in your application, you need to take the following simple steps:

<!DOCTYPE html>
<html>
    <head>
        <title>How to Start with dhtmlxCalendar</title>         
        <script type="text/javascript" src="../../codebase/calendar.js"></script>
        <link rel="stylesheet" href="../../codebase/calendar.css">
    </head>
    <body>
        <div id="calendar_container"></div>
        <script>
            // creating dhtmlxCalendar 
            var calendar = new dhx.Calendar("calendar_container");
</script> </body> </html>

Related sample:  Calendar. Basic Initialization

Include source files

Create an HTML file and place full paths to JS and CSS files of dhtmlxCalendar into the header of the created file. The Calendar component can be used standalone or as a part of the Suite library.

If you use dhtmlxCalendar standalone, you need to include 2 files:

  • calendar.js
  • calendar.css
<link type="text/css" href="../codebase/calendar.css">
<script src="../codebase/calendar.js" type="text/javascript"></script>

If you use dhtmlxCalendar as a part of the Suite package, you need to include JS/CSS files of the dhtmlxSuite library:

  • suite.js
  • suite.css
<link type="text/css" href="../codebase/suite.css">
<script src="../codebase/suite.js" type="text/javascript"></script>

Initialize Calendar

You can initialize Calendar in a container or in a popup.

Initialization in a container

In this case you initialize Calendar with the dhx.Calendar object constructor. The constructor takes two parameters:

  • the HTML container for Calendar,

index.html

<div id="calendar_container"></div>
  • an object with configuration properties (see the full list below). If this argument is not passed to the constructor, the settings will be default.

index.html

// creating dhtmlxCalendar
var calendar = new dhx.Calendar("calendar_container",{
   // config options
});

Related sample:  Calendar. Basic Initialization

Initialization in a popup

This variant pressupposes that you create a popup first and then attach a calendar into it, thus creating a date picker.

date_picker

  • create an input to enter a date into and give it the id "date-input":
<input type="text" id="date-input" style="width: 200px;" readonly/>
  • use corresponding object constructors to create a calendar and a popup objects. Note that in this case null is used instead of container for Calendar:
var calendar = new dhx.Calendar(null, {dateFormat: "%d/%m/%y"});
var popup = new dhx.Popup();
  • attach the calendar to the popup using the attach method of Popup:
popup.attach(calendar);
  • use the show method of Popup inside a click handler to define that a popup with calendar will open on click in the "date-input" input:
var dateInput = document.getElementById("date-input");
dateInput.addEventListener("click", function() {
    popup.show(dateInput);
});
  • define the logic of closing the popup with calendar using the hide method of Popup. For example, on selecting a new date in the calendar:
calendar.events.on("change", function() {
    dateInput.value = calendar.getValue();
    popup.hide();
});

Related sample:  Calendar. Date Picker

Configuration properties

There is a list of properties that you can specify in the Calendar configuration object (the second parameter of the constructor function):

css adds style classes to Calendar
date defines the date that will be opened when the calendar is created, differs from the selected date (set by value)
dateFormat defines the format of dates in –°alendar, "%d/%m/%y" by default
disabledDates allows disabling some date intervals, day labels are dimmed
mark adds a CSS class to specific days
mode the mode of Calendar initialization: "calendar" (default), "month", "year"
range enables/disables the possibility to select a range of dates on the calendar
thisMonthOnly hides dates of the previous/next months relative to the currently displayed one
timeFormat defines the time format for a timepicker in the calendar: 12-hour or 24-hour (12 or 24 (default), correspondingly)
timePicker adds a timepicker into the calendar, false by default
value selects the day (adds a round blue marker)
weekNumbers defines whether to show the numbers of weeks, false by default
weekStart sets the starting day of the week: "monday" or "sunday" (default)
width adds a timepicker into a calendar, false by default

The detailed information on configuration options can be found in the Configuration article.

Select initial date (optional)

You can specify what date should be selected in the calendar both before and after initialization of the component:

  • via the value configuration option:

index.html

var calendar = new dhx.Calendar("calendar_container", {
    value: new Date(2019,1,10)
});

index.html

var calendar = new dhx.Calendar("calendar_container", {
    // configuration options
});
calendar.setValue(new Date(2019,1,10));

Related sample:  Calendar. Preset Selected Date

Back to top