jQuery Scheduler: Vacation Planner (Timeline Year)
A team's vacations for the year on jqxScheduler's timeline year view: a row a person, a column a day under a header a month. Drag a vacation to another week or person, stretch it, or double-click a day to add one; nobody has two vacations at once, and the days off add up per person against their allowance.
A live JavaScript/jQuery example of jqxScheduler, the jQWidgets Scheduler component, with its complete source code below. It is one of 45 jqxScheduler demos for jQuery.
jqxScheduler API used in this demo
allowOverlap property – Sets or gets whether appointments may overlap.
appointmentDataFields property – Sets or gets the appointments data fields.
date property – Sets or gets the Scheduler's Date.
height property – Sets or gets the Scheduler's height.
localization property – Sets or gets the Scheduler's localization.
resources property – Sets or gets the Scheduler's resource object.
rowsHeight property – Sets or gets the Scheduler rows height.
source property – Sets or gets the Scheduler appointments data source.
views property – Sets or gets the Scheduler's views.
view property – Sets or gets the Scheduler's view.
width property – Sets or gets the Scheduler's width.
appointmentChange event – This event is triggered when an appointment is changed.
appointmentAdd event – This event is triggered when an appointment is added.
appointmentAdding event – This event is triggered before an appointment is added - from the edit dialog, the addAppointment method or the AI module - and can cancel it.
getAppointments method – Gets the appointments loaded in jqxScheduler.
Source code
To run it in your own page, load jqx.base.css, a theme and the library files below from npm (npm install jqwidgets-scripts) or the jsDelivr CDN, then add the markup and the script. jQuery is not required: jqxcore.js provides $. Getting started with jqxScheduler shows the setup step by step.
The page loads jqx.base.css, a theme and these library files: jqxcore.js, jqxbuttons.js, jqxscrollbar.js, jqxdata.js, jqxdate.js, jqxscheduler.js, jqxscheduler.api.js, jqxdatetimeinput.js, jqxmenu.js, jqxcalendar.js, jqxtooltip.js, jqxwindow.js, jqxcheckbox.js, jqxlistbox.js, jqxdropdownlist.js, jqxnumberinput.js, jqxradiobutton.js, jqxinput.js.
It also loads helper scripts of this demo site, which are not part of the library: demos.js (getWidth() and other layout helpers).
script.js
$(document).ready(function () {
// Five people, 25 days of allowance each. A vacation is an all-day appointment of its person.
var people = ['Alex Morgan', 'Bea Novak', 'Chris Diaz', 'Dana Lee', 'Eli Brooks'];
var allowance = 25;
var span = function (person, fromMonth, fromDay, toMonth, toDay, subject) {
return { subject: subject || 'Vacation', person: person, start: new Date(2026, fromMonth - 1, fromDay), end: new Date(2026, toMonth - 1, toDay, 23, 59) };
};
var vacations = [
span(people[0], 2, 16, 2, 20, 'Ski trip'), span(people[0], 7, 13, 7, 31, 'Summer'), span(people[0], 12, 21, 12, 24),
span(people[1], 4, 6, 4, 10), span(people[1], 8, 3, 8, 21, 'Summer'), span(people[1], 10, 26, 10, 30),
span(people[2], 1, 26, 1, 30), span(people[2], 6, 15, 6, 26, 'Summer'), span(people[2], 9, 21, 9, 25), span(people[2], 11, 23, 11, 27),
span(people[3], 3, 30, 4, 3), span(people[3], 7, 20, 8, 7, 'Summer'), span(people[3], 12, 14, 12, 23, 'Winter'),
span(people[4], 5, 25, 5, 29), span(people[4], 8, 17, 9, 4, 'Summer'), span(people[4], 11, 2, 11, 6), span(people[4], 12, 28, 12, 31)
];
$.each(vacations, function (i) { this.id = 'v' + i; });
var source = {
dataType: 'array',
dataFields: [
{ name: 'id', type: 'string' },
{ name: 'subject', type: 'string' },
{ name: 'person', type: 'string' },
{ name: 'start', type: 'date' },
{ name: 'end', type: 'date' }
],
id: 'id',
localData: vacations
};
var peopleSource = { dataType: 'array', dataFields: [{ name: 'person', type: 'string' }], localData: $.map(people, function (p) { return { person: p }; }) };
$('#scheduler').jqxScheduler({
date: new $.jqx.date(2026, 7, 1),
width: '100%',
height: 420,
rowsHeight: 44,
source: new $.jqx.dataAdapter(source),
view: 'timelineYearView',
// Monday first, as the weekends then fall at the end of each week
localization: { firstDay: 1 },
resources: { colorScheme: 'scheme02', dataField: 'person', orientation: 'vertical', source: new $.jqx.dataAdapter(peopleSource) },
appointmentDataFields: { from: 'start', to: 'end', id: 'id', subject: 'subject', resourceId: 'person' },
views: [{ type: 'timelineYearView', timeSlotWidth: 30 }, 'monthView', 'yearView'],
// nobody is away twice at once
allowOverlap: false
});
var status = function (ok, text) {
$('#status').removeClass('ok no').addClass(ok ? 'ok' : 'no').text(text);
};
$('#scheduler').on('appointmentAdding appointmentChanging', function (event) {
if (event.args.cancel && event.args.reason) {
status(false, event.args.reason.message + '.');
}
});
$('#scheduler').on('appointmentChange', function (event) {
var a = event.args.appointment;
status(true, a.resourceId + ': ' + a.subject + ', ' + a.from.toDate().toDateString() + ' - ' + a.to.toDate().toDateString() + '.');
});
// ---- days off per person: the weekdays a vacation covers ----
var weekdays = function (from, to) {
var count = 0;
for (var d = new Date(from.getFullYear(), from.getMonth(), from.getDate()); d < to; d.setDate(d.getDate() + 1)) {
if (d.getDay() !== 0 && d.getDay() !== 6) count++;
}
return count;
};
var renderDays = function () {
var days = {};
$.each(people, function () { days[this] = 0; });
$.each($('#scheduler').jqxScheduler('getAppointments'), function () {
if (days[this.resourceId] !== undefined) {
days[this.resourceId] += weekdays(this.from.toDate(), this.to.toDate());
}
});
$('#days tbody').empty().append($.map(people, function (person) {
var used = days[person], over = used > allowance;
return $('<tr></tr>').toggleClass('over', over)
.append($('<td></td>').text(person))
.append($('<td class="num"></td>').text(used + ' of ' + allowance))
.append($('<td></td>').append($('<div class="bar"></div>').css('width', Math.min(100, used / allowance * 100) + '%')))
.append($('<td class="note"></td>').text(over ? (used - allowance) + ' over' : ''));
}));
};
$('#scheduler').on('appointmentAdd appointmentChange appointmentDelete', renderDays);
renderDays();
});
body.html
<div id="content" class="demo">
<p class="demo-intro">
The team's year, a row a person. Drag a vacation to another week or person, stretch it from either end, or double-click a day to add one - nobody can be away twice at once. The month names stay in view as the year scrolls.
</p>
<div id="scheduler"></div>
<div id="status" class="demo-status" role="status" aria-live="polite">Days off are counted on weekdays, against an allowance of 25.</div>
<table id="days" class="demo-days">
<thead><tr><th>Person</th><th>Days off</th><th style="width: 50%">Allowance used</th><th></th></tr></thead>
<tbody></tbody>
</table>
</div>
Learn more
More jQuery Scheduler demos
- Default Functionality – The Default Functionality demo of the jQuery Scheduler.
- Year View – jqxScheduler's year view shows the twelve months at once, each day with appointments marked with a dot an appointment colour and a tooltip of what is on. Click a day - or press Enter on it - to open it in the day view; the arrow keys, Home, End, Page Up and Page Down move through the year.
- Undo and Redo – jqxScheduler records the changes made to its appointments - moved, resized, edited, added or deleted - so that they can be undone and redone with the undo and redo methods or with Ctrl+Z and Ctrl+Y.
- Save Changes in a Batch – Edits made in jqxScheduler are kept as unsaved changes and saved in one batch. The list of changes - and the request that would go to the server - follow every edit, undo and redo; Discard takes them all back with undo, and while a save is under way appointmentAdding, appointmentChanging and appointmentDeleting turn edits down, with a reason the edit dialog shows.
- Booking Rules and Blocked Times – jqxScheduler keeps bookings out of blocked times - here outside office hours and while Room 3 is cleaned - and, with allowOverlap set to false, stops a room being booked twice. appointmentAdding, appointmentChanging and appointmentDeleting say why a change was turned down, and let the application add rules of its own: here the board meeting cannot be deleted.