Rental Availability

Use the multiple month view of the date picker for building an availability calendar for a vacation rental. The colored backgrounds and labels can be used to display season and pricing information and half-day styling to show check-in and check-out dates.

Booked dates are disabled and validation on check-in and check-out dates is automatic based on the data as a range for a new booking is applied.

Get started with this example

Demo

Loading the live demo

Preview in full screen

Code

import { CommonModule } from '@angular/common';
import { HttpClient } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
import { formatDate, MbscModule, setOptions  } from '@mobiscroll/angular';

setOptions({
  locale:  ,
  theme: ' ',
  themeVariant: ' '
});

const now = new Date();

@Component({
  selector: 'app-root', 
  templateUrl: './app.component.html',
  standalone: true,
  imports: [CommonModule, MbscModule],
})
export class AppComponent implements OnInit {
  constructor(private http: HttpClient) {}

  min = '2026-10-21T00:00';
  labels: any = [];
  invalid: any = [];
  colors: any = [];
  monthColors = [
    {
      background: '#b2f1c080',
      start: '2026-01-01T00:00',
      end: '2026-01-31T00:00',
      cellCssClass: 'md-book-rental-bg-off',
      recurring: {
        repeat: 'yearly',
        month: 1,
        day: 1,
      },
    },
    {
      background: '#b2f1c080',
      start: '2026-02-01T00:00',
      end: '2026-02-28T00:00',
      cellCssClass: 'md-book-rental-bg-off',
      recurring: {
        repeat: 'yearly',
        month: 2,
        day: 1,
      },
    },
    {
      background: '#b2f1c080',
      cellCssClass: 'md-book-rental-bg-off',
      recurring: {
        repeat: 'yearly',
        month: 2,
        day: 29,
      },
    },
    {
      background: '#a3cdff80',
      start: '2026-03-01T00:00',
      end: '2026-03-31T23:59',
      cellCssClass: 'md-book-rental-bg-pre',
      recurring: {
        repeat: 'yearly',
        month: 3,
        day: 1,
      },
    },
    {
      background: '#a3cdff80',
      start: '2026-04-01T00:00',
      end: '2026-04-30T00:00',
      cellCssClass: 'md-book-rental-bg-pre',
      recurring: {
        repeat: 'yearly',
        month: 4,
        day: 1,
      },
    },
    {
      background: '#a3cdff80',
      start: '2026-05-01T00:00',
      end: '2026-05-31T00:00',
      cellCssClass: 'md-book-rental-bg-pre',
      recurring: {
        repeat: 'yearly',
        month: 5,
        day: 1,
      },
    },
    {
      background: '#f7f7bb80',
      start: '2026-06-01T00:00',
      end: '2026-06-30T00:00',
      cellCssClass: 'md-book-rental-bg-in',
      recurring: {
        repeat: 'yearly',
        month: 6,
        day: 1,
      },
    },
    {
      background: '#f7f7bb80',
      start: '2026-07-01T00:00',
      end: '2026-07-31T00:00',
      cellCssClass: 'md-book-rental-bg-in',
      recurring: {
        repeat: 'yearly',
        month: 7,
        day: 1,
      },
    },
    {
      background: '#f7f7bb80',
      start: '2026-08-01T00:00',
      end: '2026-08-31T00:00',
      cellCssClass: 'md-book-rental-bg-in',
      recurring: {
        repeat: 'yearly',
        month: 8,
        day: 1,
      },
    },
    {
      background: '#f7f7bb80',
      start: '2026-09-01T00:00',
      end: '2026-09-30T00:00',
      cellCssClass: 'md-book-rental-bg-in',
      recurring: {
        repeat: 'yearly',
        month: 9,
        day: 1,
      },
    },
    {
      background: '#f7f7bb80',
      start: '2026-10-01T00:00',
      end: '2026-10-31T23:59',
      cellCssClass: 'md-book-rental-bg-in',
      recurring: {
        repeat: 'yearly',
        month: 10,
        day: 1,
      },
    },
    {
      background: '#b2f1c080',
      start: '2026-11-01T00:00',
      end: '2026-11-30T00:00',
      cellCssClass: 'md-book-rental-bg-off',
      recurring: {
        repeat: 'yearly',
        month: 11,
        day: 1,
      },
    },
    {
      background: '#b2f1c080',
      start: '2026-12-01T00:00',
      end: '2026-12-31T00:00',
      cellCssClass: 'md-book-rental-bg-off',
      recurring: {
        repeat: 'yearly',
        month: 12,
        day: 1,
      },
    },
  ];

  getColors(start: Date, end: Date) {
    return [
      {
        date: start,
        cellCssClass: 'vacation-check-in',
      },
      {
        date: end,
        cellCssClass: 'vacation-check-out',
      },
      {
        start: new Date(start.getFullYear(), start.getMonth(), start.getDate() + 1),
        end: new Date(end.getFullYear(), end.getMonth(), end.getDate() - 1),
        background: '#ffbaba80',
        cellCssClass: 'vacation-booked',
      },
    ];
  }

  ngOnInit(): void {
    const y = now.getFullYear();
    const m = now.getMonth();
    this.http.jsonp('https://trial.mobiscroll.com/getrentals/?year=' + y + '&month=' + m, 'callback').subscribe((data: any) => {
      const prices = data.prices;
      const bookings = data.bookings;
      const labels: any = [];
      const invalids: any = [];
      let colors: any = [];
      let endDate = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0);

      for (const price of prices) {
        const booked = bookings.find((b: { checkIn: any }) => formatDate('YYYY-M-D', new Date(b.checkIn)) === price.date);
        if (booked) {
          const checkIn = new Date(booked.checkIn);
          const checkOut = new Date(booked.checkOut);
          const newCheckOut = new Date(checkOut.getFullYear(), checkOut.getMonth(), checkOut.getDate() - 1);
          colors = [...colors, ...this.getColors(checkIn, checkOut)];
          labels.push({
            start: checkIn,
            end: newCheckOut,
            text: 'booked',
            textColor: '#1e1e1ecc',
          });
          invalids.push({
            start: checkIn,
            end: newCheckOut,
          });
          endDate = checkOut;
        } else if (new Date(price.date) >= endDate) {
          labels.push({
            date: new Date(price.date),
            text: price.text,
            textColor: price.textColor,
          });
        }
      }
      this.labels = labels;
      this.invalid = invalids;
      this.colors = [...colors, ...this.monthColors];
    });
  }
}

Duplicate Session

You have signed in on a different machine. To keep everything in sync, you have been signed out of this session.

If you need to invite team members, manage seats and accounts you can do it from the licenses page.

Duplicate Session

We noticed you are logged in on a different machine and have closed your old session.

If you need to invite team members, manage seats and accounts you can do it from the licenses page.