---
title: "Javascript Scheduler Custom Range View Example | Mobiscroll"
component: "Scheduler"
framework: "JavaScript"
library_version: "6.1.5"
url: "https://demo.mobiscroll.com/javascript/scheduler/custom-range-view"
---

# Custom Range View - JavaScript Scheduler demo

Configure the Javascript Scheduler with a custom date range view — let users pick any date span from a header range picker instead of fixed day. Plain JavaScript API.

- [Live demo](https://demo.mobiscroll.com/javascript/scheduler/custom-range-view)
- [View code on GitHub](https://github.com/acidb/mobiscroll-demos-javascript/tree/main/src/demos/eventcalendar/scheduler/custom-range-view)
- This demo in other frameworks: [jQuery](https://demo.mobiscroll.com/jquery/scheduler/custom-range-view.md), [Angular](https://demo.mobiscroll.com/angular/scheduler/custom-range-view.md), [React](https://demo.mobiscroll.com/react/scheduler/custom-range-view.md), [Vue](https://demo.mobiscroll.com/vue/scheduler/custom-range-view.md)

## Description

The scheduler comes with [built-in support for day, week and month views](https://demo.mobiscroll.com/javascript/scheduler/display-multiple-days-weeks). For those situations where a custom range makes more sense, it is possible to override the calendar navigation component with a [range picker](https://demo.mobiscroll.com/javascript/range/date-filtering-with-predefined-ranges).

The calendar header can be easily customized and a two-way synchronization needs to be kept between the scheduler and range picker.

## What this demo shows

- A desktop scheduler layout with a custom date range in the header, a fixed all-day row below it, and a vertically scrollable time grid for the selected range.
- **Header** The header shows the selected custom date range on the left. Clicking the displayed range opens an anchored range picker where users can choose a custom scheduler range instead of using only fixed day, week, month, or year views.
- **Header navigation** The previous and next controls and the Today button let users move through the scheduler range and return to the current day.
- **Custom range view** The fixed strip below the header displays the days in the selected range, with the current date highlighted.
- **All-day events** All-day events appear in a dedicated row that stays fixed above the time grid.
- **Time grid** The scheduler grid scrolls vertically through the hours of the selected custom range.
- **Timed events** Timed events appear as colored cards in the scheduler grid, showing the start and end time above the event title.
- **Event overlapping** Overlapping events are displayed side by side so every event remains visible.
- **Current time** A current-time indicator appears across the scheduler grid.
- **Hover behavior** Hovering over the time grid shows a time indicator that follows the cursor in 15-minute increments.
- **Event interaction** Hovering over events highlights them and displays drag and resize handles for editing.
- **Event creation** Users can create events by double-clicking the grid or by clicking and dragging across a time range.

## Best for

- **Conference and event planning** Coordinate multi-day conferences, trade shows, workshops, festivals, corporate events, meetings, and sessions.
- **Project and program management** Track project phases, milestones, launches, deadlines, and team activities across several weeks in a single scheduler view.
- **Business travel and itineraries** Plan business trips, tours, client visits, training programs, and travel schedules while keeping appointments visible.
- **Marketing and campaign planning** Manage campaigns, content schedules, product launches, promotional events, and key milestones over extended periods.

## API used in this demo

- [`theme`](https://mobiscroll.com/docs/javascript/eventcalendar/api#opt-theme) - option
- [`themeVariant`](https://mobiscroll.com/docs/javascript/eventcalendar/api#opt-themeVariant) - option
- [`clickToCreate`](https://mobiscroll.com/docs/javascript/eventcalendar/api#opt-clickToCreate) - option
- [`dragToCreate`](https://mobiscroll.com/docs/javascript/eventcalendar/api#opt-dragToCreate) - option
- [`dragToMove`](https://mobiscroll.com/docs/javascript/eventcalendar/api#opt-dragToMove) - option
- [`dragToResize`](https://mobiscroll.com/docs/javascript/eventcalendar/api#opt-dragToResize) - option
- [`eventDelete`](https://mobiscroll.com/docs/javascript/eventcalendar/api#opt-eventDelete) - option
- [`view`](https://mobiscroll.com/docs/javascript/eventcalendar/api#opt-view) - option
- [`renderHeader`](https://mobiscroll.com/docs/javascript/eventcalendar/api#renderer-renderHeader) - renderer
- [`onPageLoaded`](https://mobiscroll.com/docs/javascript/eventcalendar/api#event-onPageLoaded) - event
- [`select`](https://mobiscroll.com/docs/javascript/datepicker/api#opt-select) - option
- [`display`](https://mobiscroll.com/docs/javascript/datepicker/api#opt-display) - option
- [`showOverlay`](https://mobiscroll.com/docs/javascript/datepicker/api#opt-showOverlay) - option
- [`touchUi`](https://mobiscroll.com/docs/javascript/datepicker/api#opt-touchUi) - option
- [`buttons`](https://mobiscroll.com/docs/javascript/datepicker/api#opt-buttons) - option
- [`onClose`](https://mobiscroll.com/docs/javascript/datepicker/api#event-onClose) - event
- [`navigate`](https://mobiscroll.com/docs/javascript/eventcalendar/api#method-navigate) - method
- [`setOptions`](https://mobiscroll.com/docs/javascript/eventcalendar/api#method-setOptions) - method
- [`refDate`](https://mobiscroll.com/docs/javascript/eventcalendar/api#opt-refDate) - option
- [`setEvents`](https://mobiscroll.com/docs/javascript/eventcalendar/api#method-setEvents) - method

## Code

### JS

```js
mobiscroll.setOptions({
  theme: 'ios',
  themeVariant: 'light'
});

var formatDate = mobiscroll.formatDate;
var startDate;
var endDate;
var end;

var myCalendar = mobiscroll.eventcalendar('#demo-custom-range-view', {
  clickToCreate: true,
  dragToCreate: true,
  dragToMove: true,
  dragToResize: true,
  eventDelete: true,
  view: {
    scheduler: {
      type: 'day',
      size: 14,
    },
  },
  renderHeader: function () {
    return (
      '<div id="custom-date-range"><button mbsc-button data-variant="flat" class="mbsc-calendar-button">' +
      '<span id="custom-date-range-text" class="mbsc-calendar-title">Button' +
      '</span></button></div>' +
      '<div class="md-custom-range-view-controls">' +
      '<div mbsc-calendar-prev></div>' +
      '<div mbsc-calendar-today></div>' +
      '<div mbsc-calendar-next></div>' +
      '</div>'
    );
  },
  onPageLoaded: function (args) {
    startDate = args.firstDay;
    end = args.lastDay;
    endDate = new Date(end.getFullYear(), end.getMonth(), end.getDate() - 1, 0);
    // Set button text
    rangeButton.innerText = getFormattedRange(startDate, endDate);
    // Set range value
    myRange.setVal([startDate, endDate]);
  },
});

var myRange = mobiscroll.datepicker('#custom-date-range', {
  select: 'range',
  display: 'anchored',
  showOverlay: false,
  touchUi: true,
  buttons: [],
  onClose: function (args, inst) {
    var date = inst.getVal();
    if (date[0] && date[1]) {
      if (date[0].getTime() !== startDate.getTime()) {
        // Navigate the calendar
        myCalendar.navigate(date[0]);
      }
      startDate = date[0];
      endDate = date[1];
      // Set calendar view
      myCalendar.setOptions({
        refDate: startDate,
        view: {
          scheduler: {
            type: 'day',
            size: getNrDays(startDate, endDate),
          },
        },
      });
    } else {
      myRange.setVal([startDate, endDate]);
    }
  },
});

var rangeButton = document.getElementById('custom-date-range-text');

// Returns the formatted date
function getFormattedRange(start, end) {
  return (
    formatDate('MMM D, YYYY', new Date(start)) +
    (end && getNrDays(start, end) > 1 ? ' - ' + formatDate('MMM D, YYYY', new Date(end)) : '')
  );
}

// Returns the number of days between two dates
function getNrDays(start, end) {
  return Math.round(Math.abs((end.setHours(0) - start.setHours(0)) / (24 * 60 * 60 * 1000))) + 1;
}

mobiscroll.getJson(
  'https://trial.mobiscroll.com/events/?vers=5',
  function (events) {
    myCalendar.setEvents(events);
  },
  'jsonp',
);
```

### HTML

```html
<div id="demo-custom-range-view"></div>
```

### CSS

```css
.md-custom-range-view-controls {
  display: flex;
  flex: 1 0 auto;
  justify-content: end;
  align-items: center;
}
```

## Implementation notes

- Use `view: { scheduler: { type: 'day', size: 14 } }` - a multi-day scheduler where `size` is the number of days shown simultaneously. The initial value is 14; it is updated dynamically whenever the user selects a new range.
- Render a custom header containing: a `Datepicker` in `select: 'range'` mode anchored to a button, a button displaying the formatted current date range, and `CalendarPrev`, `CalendarToday`, `CalendarNext` navigation controls.
- Configure the `Datepicker` with `display: 'anchored'`, `showOverlay: false`, `touchUi: true`, and `buttons: []` (no footer buttons). Anchor it to the date-range button element so it opens positioned directly below it.
- **Two-way sync**: On `onPageLoading` (React/Angular) or `onPageLoaded` (Vue/JS/jQuery), update the button text and datepicker range value to reflect the current calendar page. On datepicker `onClose`, calculate the number of days in the selected range, set `view.scheduler.size` to that count, and navigate the calendar to the range start date.
- Load events from `https://trial.mobiscroll.com/events/?vers=5` via JSONP using `getJson(url, callback, 'jsonp')`. React/Angular/Vue: assign the fetched array to the state/property bound to the `data` prop. JS/jQuery (imperative API): call `inst.setEvents(events)` in the callback.

## Run it in your project

1. If not signed up yet, or don't own a license, you can [start a free trial](https://mobiscroll.com/starttrial).

2. Clone the repository:

   ```
   git clone https://github.com/acidb/mobiscroll-demos-javascript.git
   ```

3. If not installed yet, install the Mobiscroll CLI from NPM:

   ```
   npm install -g @mobiscroll/cli
   ```

4. Config Mobiscroll - open a terminal window in the root directory and run:

   ```
   mobiscroll config javascript
   ```

5. Install dependencies - open a terminal window in the root directory and run:

   ```
   npm install
   ```

6. Run the project:

   ```
   npm run dev
   ```

On a trial, add `--trial` to the config command: `mobiscroll config javascript --trial`.

Running a demo locally requires a Mobiscroll trial or a license; setup is per framework at https://mobiscroll.com/docs/javascript/getting-started/installation

## Related demos

- Next: [Limit Overlapping Events](https://demo.mobiscroll.com/javascript/scheduler/control-number-of-concurrently-shown-events.md) - Set a max count or auto-fit overlapping events to available space in the Javascript Scheduler — useful for appointment-heavy views.
