Skip to main content

DHTMLX Booking. Card fields example

Live example​

Each card shows a fixed set of fields on its left side, and cardShape decides which of them are visible. A field set to false disappears from every card. This demo turns off subtitle, price, and review, so the list keeps the preview image, the category, the name, and the address.

const widget = new booking.Booking("#root", {
	start: buildToday(),
    cardShape: {
        subtitle: false,
        price: false,
        review: false,
    },      
    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>

Use case​

Not every field makes sense in every deployment. An internal room and equipment screen has no price to show, and a public service portal has no star ratings. A dispatcher picking a technician needs the name and the address, not the marketing text. The same records can then serve several screens: keep the full data in data and let each screen choose what it puts in front of its users. Adding a field back is one boolean, so a customer who wants the rating after all does not need a new build of the card.

How to do this in your app​

  • Pass the object: cardShape: { subtitle: false, price: false, review: false } hides those three fields on every card.
  • Name only what changes: keys you leave out keep their defaults. All seven are on: category, details, preview, price, review, subtitle, and title.
  • Start from the defaults when you prefer them explicit: const { defaultCardShape } = booking gives you that object to spread into your own.
  • Optional, rebuild the card instead: cardTemplate replaces the whole left block with your own HTML, as in the card template demo.

Good to know​

  • subtitle starts visible: years of experience show until you set subtitle: false, as this demo does.
  • A template overrides the shape: when cardTemplate and cardShape are both set, the template decides what the card looks like.
  • The booking dialog is configured separately: infoShape controls the fields in the dialog, so hiding the price on a card leaves the dialog untouched.

FAQ​

How do you hide the price or the rating on a booking card?​

Pass cardShape with price: false and review: false. Every key in the object is a boolean, and only the ones you name are changed.

Which fields does a booking card show by default?​

The preview image, the category, the title, the subtitle, the details, the price, and the rating. All seven start visible.

How do you change the layout of a card and not only its fields?​

Use cardTemplate, as in the card template demo. It replaces the card block with your own HTML, so the fields can be reordered, extended, and styled with your own CSS classes.

API reference​

Additional resources​