| Doctor | Visits | Booked |
|---|
| Doctor | Visits | Booked |
|---|
A clinic's booking desk built on jqxScheduler: findAvailableSlots offers the next free times for a visit, blockedTimes keeps bookings inside opening hours and away from lunch and days off, minDuration and maxDuration limit a visit to 15-60 minutes, and allowOverlap: false stops a doctor being booked twice.
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.
allowOverlap property – Sets or gets whether appointments may overlap.blockedTimes property – Sets or gets the times that cannot be booked: an array of { from, to, resourceId, recurrenceRule, text }.maxDuration property – Sets or gets the longest an appointment may last, in minutes; null for no limit.minDuration property – Sets or gets the shortest an appointment may last, in minutes; null for no limit.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.ready property – Sets a function called when the Scheduler is rendered and ready for usage.resources property – Sets or gets the Scheduler's resource object.rowsHeight property – Sets or gets the Scheduler rows height.showLegend property – Sets or gets whether the Scheduler's legend bar is displayed.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.addAppointment method – Adds a new appointment.findAvailableSlots method – Returns free times for a new appointment, earliest first: [{ from, to, resourceId }], from and to as $.jqx.date values.getAppointments method – Gets the appointments loaded in jqxScheduler.scrollToTime method – Scrolls the day or week view so that a time of day is at its top, for example the start of the working day.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).
$(document).ready(function () {
// The week of 16 November 2026 at a small clinic. Visits are appointments, the doctors are
// resources. The clinic's own rules are settings - opening hours, lunch, weekends and
// Dr. Okafor's Wednesday off are blockedTimes; a visit lasts 15 to 60 minutes; a doctor is
// never booked twice - so every way of booking obeys them: the form below, dragging,
// resizing and the edit dialog.
var doctors = ['Dr. Ana Petrova', 'Dr. Ben Okafor', 'Dr. Chen Wei'];
var at = function (day, hour, minute) { return new Date(2026, 10, day, hour, minute || 0); };
var visits = [
{ id: 'v1', patient: 'Ivan Georgiev', type: 'Check-up', doctor: doctors[0], start: at(16, 8, 30), end: at(16, 8, 45) },
{ id: 'v2', patient: 'Maria Lopez', type: 'Consultation', doctor: doctors[0], start: at(16, 9, 0), end: at(16, 9, 30) },
{ id: 'v3', patient: 'Sam Carter', type: 'Procedure', doctor: doctors[0], start: at(16, 10, 0), end: at(16, 11, 0) },
{ id: 'v4', patient: 'Lena Fischer', type: 'Vaccination', doctor: doctors[1], start: at(16, 8, 0), end: at(16, 8, 15) },
{ id: 'v5', patient: 'Noah Kim', type: 'Consultation', doctor: doctors[1], start: at(16, 9, 30), end: at(16, 10, 0) },
{ id: 'v6', patient: 'Olga Ivanova', type: 'Check-up', doctor: doctors[1], start: at(16, 14, 0), end: at(16, 14, 15) },
{ id: 'v7', patient: 'Priya Shah', type: 'Procedure', doctor: doctors[2], start: at(16, 8, 0), end: at(16, 9, 0) },
{ id: 'v8', patient: 'Tom Becker', type: 'Consultation', doctor: doctors[2], start: at(16, 11, 0), end: at(16, 11, 30) },
{ id: 'v9', patient: 'Ana Silva', type: 'Check-up', doctor: doctors[2], start: at(16, 15, 0), end: at(16, 15, 15) },
{ id: 'v10', patient: 'Jonas Berg', type: 'Consultation', doctor: doctors[0], start: at(17, 9, 0), end: at(17, 9, 30) }
];
$.each(visits, function () { this.subject = this.patient + ' - ' + this.type; });
var source = {
dataType: 'array',
dataFields: [
{ name: 'id', type: 'string' },
{ name: 'subject', type: 'string' },
{ name: 'doctor', type: 'string' },
{ name: 'start', type: 'date' },
{ name: 'end', type: 'date' }
],
id: 'id',
localData: visits
};
// every doctor is a column, booked or not
var doctorSource = { dataType: 'array', dataFields: [{ name: 'doctor', type: 'string' }], localData: $.map(doctors, function (d) { return { doctor: d }; }) };
var openingHours = { fromDayOfWeek: 1, toDayOfWeek: 5, fromHour: 8, toHour: 17 };
$('#scheduler').jqxScheduler({
date: new $.jqx.date(2026, 11, 16),
width: '100%',
height: 560,
source: new $.jqx.dataAdapter(source),
view: 'dayView',
showLegend: true,
// quarter-hour rows, and no all-day row: visits have times
rowsHeight: 24,
showAllDayRow: false,
resources: {
colorScheme: 'scheme02',
dataField: 'doctor',
orientation: 'horizontal',
source: new $.jqx.dataAdapter(doctorSource)
},
appointmentDataFields: { from: 'start', to: 'end', id: 'id', subject: 'subject', resourceId: 'doctor' },
views: [
{ type: 'dayView', workTime: openingHours, timeRuler: { scale: 'fifteenMinutes', scaleStartHour: 7, scaleEndHour: 18 } }
],
// the clinic's rules
blockedTimes: [
{ from: at(1, 0, 0), to: at(1, 8, 0), recurrenceRule: 'FREQ=DAILY', text: 'Closed' },
{ from: at(1, 17, 0), to: at(2, 0, 0), recurrenceRule: 'FREQ=DAILY', text: 'Closed' },
{ from: at(2, 12, 30), to: at(2, 13, 30), recurrenceRule: 'FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR', text: 'Lunch' },
{ from: at(7, 0, 0), to: at(8, 0, 0), recurrenceRule: 'FREQ=WEEKLY;BYDAY=SA,SU', text: 'Closed' },
{ from: at(4, 0, 0), to: at(5, 0, 0), recurrenceRule: 'FREQ=WEEKLY', resourceId: doctors[1], text: 'Day off' }
],
minDuration: 15,
maxDuration: 60,
allowOverlap: false,
ready: function () {
// the day starts at opening time
$('#scheduler').jqxScheduler('scrollToTime', 8);
}
});
// ---- the booking form ----
var visitTypes = [
{ label: 'Check-up (15 min)', value: 'Check-up', minutes: 15 },
{ label: 'Vaccination (15 min)', value: 'Vaccination', minutes: 15 },
{ label: 'Consultation (30 min)', value: 'Consultation', minutes: 30 },
{ label: 'Procedure (60 min)', value: 'Procedure', minutes: 60 }
];
// labelled by the label above it; a placeholder would float over it in some themes
$('#patient').jqxInput({ width: 190, height: 30 });
$('#patient').jqxInput('val', 'Eva Novak');
$('#visit').jqxDropDownList({ width: 190, height: 30, source: visitTypes, displayMember: 'label', valueMember: 'value', selectedIndex: 2, autoDropDownHeight: true });
$('#doctor').jqxDropDownList({ width: 170, height: 30, source: ['Any doctor'].concat(doctors), selectedIndex: 0, autoDropDownHeight: true });
$('#find').jqxButton({ height: 30 });
var pad = function (n) { return (n < 10 ? '0' : '') + n; };
var dayNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
var describe = function (date) {
var d = date.toDate();
return dayNames[d.getDay()] + ' ' + d.getDate() + ' Nov, ' + pad(d.getHours()) + ':' + pad(d.getMinutes());
};
// "Dr. Ana Petrova" -> "Dr. Petrova"
var shortName = function (doctor) {
var words = doctor.split(' ');
return words[0] + ' ' + words[words.length - 1];
};
var status = function (ok, text) {
$('#status').removeClass('ok no').addClass(ok ? 'ok' : 'no').text(text);
};
var findTimes = function () {
var type = visitTypes[$('#visit').jqxDropDownList('getSelectedIndex')];
var doctor = $('#doctor').jqxDropDownList('getSelectedIndex') > 0 ? $('#doctor').val() : null;
// the clinic's week: free times that no visit, lunch, day off or closing time is in
var slots = $('#scheduler').jqxScheduler('findAvailableSlots', {
duration: type.minutes,
resourceId: doctor || doctors,
from: new Date(2026, 10, 16), to: new Date(2026, 10, 20, 23, 59),
workTime: openingHours,
step: 15,
maxSlots: 4
});
$('#slots').empty().append($('<span class="label"></span>').text('Free:'));
if (!slots.length) {
$('#slots').append($('<span class="hint"></span>').text('No free time this week for a ' + type.value.toLowerCase() + '.'));
return;
}
$.each(slots, function (i, slot) {
var d = slot.from.toDate();
$('<button type="button"></button>')
.text(dayNames[d.getDay()] + ' ' + pad(d.getHours()) + ':' + pad(d.getMinutes()) + ' · ' + shortName(slot.resourceId))
.attr('aria-label', 'Book ' + describe(slot.from) + ' with ' + slot.resourceId)
.appendTo('#slots')
.jqxButton({ height: 30 })
.on('click', function () { book(slot, type); });
});
};
var book = function (slot, type) {
var patient = String($('#patient').val()).trim() || 'New patient';
var added = $('#scheduler').jqxScheduler('addAppointment', {
subject: patient + ' - ' + type.value, start: slot.from.toDate(), end: slot.to.toDate(), doctor: slot.resourceId
});
if (added) {
// show the day of the new visit
$('#scheduler').jqxScheduler('navigateTo', slot.from);
status(true, patient + ' is booked with ' + slot.resourceId + ', ' + describe(slot.from) + '.');
findTimes();
}
};
$('#find').on('click', findTimes);
// ---- what the rules said, and each doctor's day ----
$('#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.subject + ' moved to ' + describe(a.from) + ' with ' + a.resourceId + '.');
});
var renderDay = function () {
var day = $('#scheduler').jqxScheduler('date').toDate();
var start = new Date(day.getFullYear(), day.getMonth(), day.getDate()).getTime(), end = start + 86400000;
var appointments = $('#scheduler').jqxScheduler('getAppointments');
var rows = $.map(doctors, function (doctor) {
var minutes = 0, count = 0;
$.each(appointments, function () {
var from = this.from.toDate().getTime(), to = this.to.toDate().getTime();
if (this.resourceId === doctor && from >= start && from < end) {
count++;
minutes += (to - from) / 60000;
}
});
return $('<tr></tr>')
.append($('<td></td>').text(doctor))
.append($('<td class="num"></td>').text(count))
.append($('<td class="num"></td>').text(Math.floor(minutes / 60) + ' h ' + pad(minutes % 60) + ' min'));
});
$('#dayTitle').text(dayNames[day.getDay()] + ' ' + day.getDate() + ' November');
$('#day tbody').empty().append(rows);
};
$('#scheduler').on('appointmentAdd appointmentChange appointmentDelete dateChange', renderDay);
renderDay();
findTimes();
});
<div id="content" class="demo">
<div class="demo-form">
<div><label for="patient">Patient</label><input type="text" id="patient"></div>
<div><label>Visit</label><div id="visit" aria-label="Visit"></div></div>
<div><label>Doctor</label><div id="doctor" aria-label="Doctor"></div></div>
<input type="button" id="find" value="Find free times">
</div>
<div id="slots" class="demo-slots" aria-live="polite" aria-label="Free times"></div>
<div id="scheduler"></div>
<div id="status" class="demo-status" role="status" aria-live="polite">Pick a free time to book it, or drag a visit to another time or doctor.</div>
<strong id="dayTitle"></strong>
<table id="day" class="demo-day">
<thead><tr><th>Doctor</th><th>Visits</th><th>Booked</th></tr></thead>
<tbody></tbody>
</table>
</div>