Skip to main content

DHTMLX Booking. Slot duration and gap example

Live example​

slotSize sets the length of one slot in minutes and slotGap sets the break after it. This demo uses 40-minute slots with a 10-minute gap for every card that does not set its own values. Barnett Mueller sets slotSize: 20 and slotGap: 10 on his card. David Thompson sets size: 50 and gap: 20 on his slot rule.

const widget = new booking.Booking("#root", {
	start: buildToday(),
    data: dataset,
    slotSize: 40,
    slotGap: 10,
});

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>
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
        },
        slots: [
            {
                from: 9,
                to: 17,
                days: [1, 2, 3, 4, 5]
            }
        ]
    },
      // ... 44 more items (see Live Editor for full data)
    ];

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();
}

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>

Use case​

Almost every service has a house rhythm. A consultation takes 40 minutes and the next 10 go to notes, a treatment room needs cleaning between visits, a test bench needs to cool down. Two numbers on the widget describe that rhythm once, and every card follows it until a card or a rule says otherwise. That is the difference between a schedule that matches how the business actually works and one that books people back to back. A card with its own rhythm uses slotSize and slotGap. A rule uses size and gap when only that part of the day changes.

How to do this in your app​

  • Set the slot length: slotSize: 40 gives every slot 40 minutes.
  • Add the break: slotGap: 10 leaves 10 minutes between one slot and the next.
  • Override for one card: Barnett Mueller sets slotSize: 20 and slotGap: 10 on the card. Those values replace the widget for every rule on that card. Either property can be set on its own.
  • Override for one rule: David Thompson's 08:00–10:00 rule sets size: 50 and gap: 20. A rule's size and gap replace the card and the widget for that rule.

Good to know​

  • The defaults are 60 and 0: a slot lasts an hour and the next one starts immediately.
  • The working hours decide the count: from and to frame the day, and the length plus the gap decide how many slots fit, so a longer slotSize produces fewer slots.
  • Overlapping rules cancel the day: when two rules cover the same day, their from–to ranges must not overlap, or the widget drops every slot for that day. Ranges that only touch are kept.

FAQ​

How do you set the length of a booking slot in JavaScript?​

Pass slotSize to the constructor with the number of minutes. It applies to every card that does not define slotSize of its own or size inside a slot rule.

How do you leave a break between two bookings?​

Set slotGap to the number of minutes to skip after each slot. The default is 0, which means the next slot starts the moment the previous one ends.

Can two cards use different slot lengths?​

Yes. slotSize and slotGap inside a card object override the widget-level values, and size and gap inside a single slots rule override the card. In this demo, Barnett Mueller is the card override and David Thompson is the rule override.

API reference​

  • slotSize: The duration of one slot for all cards
  • slotGap: The gap between two slots for all cards
  • data: Per card and per rule slot parameters
  • Configuration guide: Filling cards with slot rules

Additional resources​