Interactive Booking Examples
DHTMLX Booking is a client-side JavaScript component for showing available time slots and taking reservations. It gives you a searchable card list, working hours per card, and a booking dialog you can shape and validate. Explore the interactive demos below to see its features in action, or visit the official documentation for the full API reference.
const widget = new booking.Booking("#root", {
start: buildToday(),
data: dataset,
});
widget.setConfirmHandler(function(event){
const { confirm } = event;
setTimeout(() => {
Math.random() < 0.5 ? confirm.error() : confirm.done();
}, 1000);
});<!-- component container -->
<div id="root" style="height:100%"></div>
<!-- dataset -->
<script>
function buildToday(){const params = new URLSearchParams(typeof location !== 'undefined' ? location.search : '');const fixed = params.get('fixedDate') || (typeof window !== 'undefined' && window.FIXED_DATE);return fixed ? new Date(fixed) : new Date();}
const dataset = [
{
id: "ee828b5d-a034-420c-889b-978840015d6a",
title: "Natalie Tyson",
category: "Therapist",
subtitle: "2 years of experience",
details: "Cleveland Clinic\n9500 Euclid Ave",
preview: "https://snippet.dhtmlx.com/codebase/data/booking/01/img/01.jpg",
price: "$35",
review: {
stars: 4,
count: 120,
},
slots: [
{
from: 9,
to: 20,
days: [1, 2, 3, 4, 5],
},
{
from: 10,
to: 18,
days: [6, 0],
},
],
},
{
id: "5c9b64ad-1830-4e5b-a5f9-8acea10706df",
title: "James Anderson",
category: "Allergist",
subtitle: "3 years of experience",
details: "UCLA Medical Center\n57 Westwood Plaza",
preview: "https://snippet.dhtmlx.com/codebase/data/booking/01/img/11.jpg",
price: "$30",
review: {
stars: 4,
count: 64,
},
slotSize: 45,
slotGap: 10,
slots: [
{
from: "9:15",
to: 17,
days: [1, 2, 3, 4, 5],
},
],
},
// ... 44 more items (see Live Editor for full data)
];
function getDate(addDays, hoursValue = 0, minutesValue = 0) {
const date = buildToday();
const secondsValue = 0; // round to minutes
const msValue = 0;
date.setDate(date.getDate() + addDays);
date.setHours(hoursValue, minutesValue, secondsValue, msValue);
return date.getTime();
}
</script>Getting started
Set up the widget and the schedule:
- Initialization: build the card list, the day picker, and the slot grid from one data array
- Start and end dates: limit the schedule to a fixed period
- Slot duration and gap: set the length of a slot and the break after it
- Time format: switch slot times between a 12 hour and a 24 hour clock
- Localization: change the interface language at runtime (English, German, Chinese)
Cards and dialog
Decide what the visitor sees before and during a booking, and how it looks:
- Card fields: show or hide any field on a card, including the preview image, the price, and the rating
- Card template: rebuild the card block with your own HTML and CSS
- Booking form fields: choose the fields of the form and validate them
- Dialog info fields: trim what the booking dialog repeats about the card
- Dialog info template: print a cancellation policy, the time range, the address, and the price your way
- Styling with custom CSS: build a dark theme by redefining the widget's CSS variables
Data and performance
Feed the widget from a real system:
- Filter customization: choose the searchable fields and the time ranges, and run the search as you type
- Filtered data loading: load one region, branch, or department at a time
- Lazy rendering: keep tens of thousands of cards responsive
- Backend integration: load availability from a service and post reservations back
Framework and widget integration
Run the widget inside a framework or pair the visitor view with a planning tool:
- React integration: mount it in a ref container and destroy it on unmount
- Angular integration: create it in
ngOnInitand clean it up inngOnDestroy - Vue integration: create it when the component mounts and destroy it after
- Svelte integration: bind the container, create it in
onMount, destroy it inonDestroy - Event Calendar integration: staff plan shifts in DHTMLX Event Calendar, visitors book the free slots
- Scheduler integration: the same split, with shifts saved through Scheduler's data processor and free slots booked from the same backend