Step 3: Initialize the Scheduler
Initialize the scheduler using Daypilot .calendar class:
HTML
These simple steps will render an empty scheduler:
772022 | 7/18/2022 | 7/19/2022 | 7/20/2022 7/21/2022 7/22/20
Q™
Ops
We
2
1™
2
Step 4: Load Data
‘We will load the data to the event calendar using a simple HTTP call:
JavaScriptasync function loadEvents() {
const start = dp.visibleStart();
const end = dp.visibletnd();
// in .NET, use "/api/CaLendarévents?start=$ {start }eend=${end)"
const {data} = await DayPilot.Http.get(“backend_events. php?start=${start }&end=$(end) );
dp-update({
events: data
Ys
Since version 2018.2.232, you can also use a built-in shortcut method to load events:
JavaScript
function loadEvents() {
// in .NET, use “api/CatendarEvents”
dp.events.load("backend_events.php");
+
You can detect the currently-visible date range using visibleStart() and visibletnd() methods.
The events.load() method adds the start and end to the URL query string automatically.
The backend event php endpoint returns the calendar event data in the following format:
JavaScript
:"2@23-02-25T1@: 38:00",
2023-02-25T16: 30:00
“2,
"text":"Calendar Event 2",
1"2023-@2-247@9: 00:00",
'2023-02-24T14: 30:00
"3",
"text": "Calendar Event 3",
“start” :"2023-02-27112:00:00
end” :"2@23-@2-27116:00:00
y
1
PHP backend (backend_events.php):
PHPprepare("SELECT * FROM events WHERE NOT ((end
rend))")s
$stmt->bindParam(':start’, $_GET['start']);
$stmt->bindParam(':end", $_GET['end"});
$stmt->execute()5
$result = $stmt->fetchAll();
class Event {}
$events = array();
foreach($result as $row) {
$e = new Event();
$e-rid = Srow['id'];
$e->text = $row ‘name"];
$e-rstart = $row[ ‘start’ ];
$e-rend = Srow[*end']5
$events[] = $e;
}
echo json_encode($events) ;
>
ASP.NET Core backend (CalendarEventsController.cs)
c#
rstart) OR
(start >=
// GET: api/Catendarévents
[HttpGet]
public async Task>>
GetEvents([FromQuery] DateTime start, [FromQuery] DateTime end)
{
return await context. Events
sWhere(e => 1((e,End <= start) || (e.Start >= end)))
-ToListAsync()5
Read more about loading the calendar event data [doc.daypilot.org].
Step 5: Event Movingsunday Monday Tuesday Wednesday tt
ow
10" ps
lila
12 Event 2 Event
a
2™ Bp
la
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 (for PHP):
JavaScript
const dp = new DayPilot.Calendar("dp", {
Wve
onéventMoved: async (args) => {
const data = {
id: args.e.id(),
newsStart: args-newstart,
newEnd: args.newEnd,
await DayPilot.Http.post(*backend_move.php”, data);
console.log("The calendar event was moved.
+
Ys
PHP backend (backend_move.php):PHP.
prepare($insert);
$stmt->bindParam(':start', $params->newStart);
$stnt->bindParam(':end', $params->newEnd) ;
$stmt->bindParam(’:id’, $params->id);
$stmt->execute();
class Result {}
$response = new Result();
$response->result = OK";
Sresponse->message = ‘Update was successful’;
header( ‘Content-Type: application/ json’);
echo json_encode(Sresponse);
JavaScript event handler (for ASP.NET Core):
JavaScript
const dp = new DayPilot.calendar("dp'
MW.
onEventMoved: async (args) => (
const id = args.e.id();
const data = {
id: args.e.id(),
start: args.newStart,
end: args.newend,
text: args.e.text()
u
await DayPilot.Http.put(~ /api/Calendarevents/${id}’, data);
console.log("The calendar event was moved.");
}
Ds
ASP.NET Core backend (CalendarEventsController.cs):
cH
// PUT: api/CaLendarévents/5
[HttpPut("{id}")]
public async Task PutCalendarévent(int id, Calendar€vent calendarEvent)
tif (id I= calendarevent.1d)
t
+
return BadRequest();
_context.Entry(calendarévent).State = EntityState.Modified;
try
t
await _context.SaveChangesAsync();
?
catch (DbUpdateConcurrencyException)
{
Af (ICalendareventexists(id))
t
return NotFound();
}
else
t
throw;
}
}
return NoContent();
Read more about drag and drop event moving [doc.daypilotorg].
Step 6: Event EditingYou can use DayPilot Modal dialog to edit the events details. DayPilot Modal is an open-source library
for building modal forms from code (online Modal Dialog Builder application for visual modal dialog
design is also available).
First, we add an onEventClick event handler that is fired when users click an existing event.
Our modal dialog will have just a single form field (text value called "Name"
JavaScript
const form = [
{name: "Name", id:
i
text")
Now we can open the modal dialog using DayPilot.Modal.form() method. The second parameter
specifies the source data object. The data object will be used to fill the initial values (the id value of
the form item specifies the property/field of the data object)
The DayPilot Modal. form() method returns a promise, That means we can use the await syntax to
for the result and simplify the code:
JavaScript
const modal = await DayPilot.Modal.form(form, args.e.data);
if (modal.canceled) {
returns
}
The result is available as modal.result object. It's a copy of the original object, with the updated
values applied.
This is our onEventClick event handler:
JavaScript
const dp = new DayPilot.Calendar("dp", {
async (args) => {
c
{nane: "Name", i
ii
"eext"}
const modal = await DayPilot.Modal.form(form, args.e.data);
if (modal.canceled) {
return}
+
// PHP
const data = {
id: args.e.id(),
text: modal result.textoH
await DayPilot.Http.post(*backend_update. php’, data);
U1 NET 7
i
const id = args.e.id();
const data = {
id: args.e.id(),
start: args.e.start(),
end: args.e.end(),
text: modal.result.text
b
await DayPilot.Http.put(*/api/Calendarévents/${id}’, data);
”
dp.events .update({
---args.e.data,
text: modal.result.text
D5
console.log("The calendar event was updated.”);
}
Ds
PHP backend (backend_update.php):
PHP
prepare($insert);
$stmt->bindParam(':text', $params->text);
$stmt->execute();
class Result {}
Sresponse = new Result();
$response->result = 'OK';
$response->message = ‘Update successful’;
header( ‘Content-Type: application/json');
echo json_encode($response) ;
Step 7: Apply the CSS Theme‘16/2021 er7f202i 6/2023 69/2021
gay
10”)
Ais
125
1
If you want to use a custom CSS theme, you need to include the stylesheet:
HTML
const dp = new DayPilot.Calendar("dp'
: "Week",
‘calendar_transparent”
dp.init();
You can choose one of the included CSS themes or you can create your own using the online CSS.
theme designer.
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 [themes.daypilot.org].
Default CSS Theme12/4/2022
12/5/2022
12/6/2022
27/2022
12/8/2022
a
10"
Wu
12™
1
2™
3
Event 2
Green CSS Themeees
Traditional CSS ThemeTransparent CSS Themeteyajaone | 12/5/2022 | 12/6/2022 | 12/7/2022 | 12/8/2022
White CSS ThemeMonthly Event CalendarDayPilot also includes a monthly event calendar view. The API of the monthly view control uses the
same design as the daily/weekly calendar:
HTML
Event Calendar Localization
Select locale: |de-de ¥
Montag Dienstag Mittwoch, Donnerstag)
9°
10”
1°
2
13”
14”
You can switch the event calendar locale easily using . locale property:
HTML
The calendar includes built-in support for many following locales [api.daypil
You can also create and register your own locale:
JavaScript
DayPilot. Locale.register(
new DayPilot.Locale(‘en-us",
{
‘dayNanes’ :[ ‘Sunday’ , ‘Monday’, ‘Tuesday’ , ‘Wednesday’, "Thursday", ‘Friday’, ‘Saturday’ ],
"dayNamesShort':['Su','No','Tu','We','Th','Fr','Sa"],
*monthNames*:["January', ‘February’, ‘March’, ‘April’, ‘May,
“June’, "July", ‘August, 'September’ , ‘October, ‘November ', ‘Decenber'],
*monthNamesShort':[‘Jan‘,'Feb','Nar", ‘Apr’, ‘May’, "Jun’
“dul', Aug’, "Sep", Oct", Nov", "Dec" J,
“timePattern’ :*h:mm tt",
‘datePattern’ :'N/d/yyyy",
“dateTimePattern':'M/d/yyyy h:mm tt",
“timeFormat' : ‘Clock12Hours' ,
“weekStarts'
t
5
Changing the Scheduler Date using a Date Picker
< July 2022 > 7/17/2022 7/18/2022 7/19/2022
Su Mo Tu We Th fr Sa ge
2 30 1 2
304 5 6 7 8 9)| 4Qam Event 1
w 1 2 B 4 15 16
7 18 19 | 20] 21 22 23 yy aw
24 25 26 27 28 29 30
31 12™
August 2022
Su Mo Tu We Th fr Sa ™
78 9 Wn BB 2™
You can use the DayPilot Navigator date picker control (on the left side in the screenshot above) to
change the scheduler dates (the visible week):nav" >
Duration Bar
3/24/2013 3/25/2013 3/26/2013
Ss
11
12" Special event
1"
2a
3H
4am
3/27/2013
Version 1.1 of the DayPilot Lite HTMLS 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)6/5/2016 6/6/2036 6/7/2016 6/8/2016
reuse
rr)
Since version 1.3 SP3, DayPilot Lite supports event customization using onBeforetventRender event
handler:
dp">