---
title: "Vue Timeline Custom Range Picker View Example | Mobiscroll"
component: "Timeline"
framework: "Vue"
library_version: "6.1.5"
url: "https://demo.mobiscroll.com/vue/timeline/custom-range-view"
---

# Custom Range Picker View - Vue Timeline demo

Replace the Vue Timeline's default header navigation with a range picker — let users set any custom date range, synced two-way with the timeline. For Vue and Nuxt.

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

## Description

The timeline comes with [built-in support for day, week, month and year views](https://demo.mobiscroll.com/vue/timeline/multiple-days-weeks-months-quarters-years-variable-resolution). 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/vue/range/date-filtering-with-predefined-ranges).

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

## What this demo shows

- A desktop timeline layout with a custom date range arranged horizontally and resources arranged vertically on the left.
- **Header** The header shows the selected custom date range on the left. Clicking the displayed range opens an anchored range picker for choosing a custom range instead of relying only on fixed day, week, month, or year views.
- **Header navigation** The previous and next controls and the Today button move the timeline range backward, forward, or back 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.
- **Resources** Multiple resources are shown vertically on the left side of the timeline as individual rows.
- **Event labels** Events are rendered as colored labels inside the day cells, with the event title shown in bold.
- **Date positioning** Events are positioned according to both their assigned resource and their exact date range.
- **Event interaction** Events are highlighted on hover and show drag and resize handles for repositioning or changing duration.
- **Event selection** Clicking an event selects and highlights it.
- **Event creation** Users can create a new event by double-clicking the timeline or by clicking and dragging across it.
- **Scrolling** The timeline supports horizontal and vertical scrolling for navigating through time and resources.

## 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 one timeline 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/vue/eventcalendar/api#opt-theme) - option
- [`themeVariant`](https://mobiscroll.com/docs/vue/eventcalendar/api#opt-themeVariant) - option
- [`clickToCreate`](https://mobiscroll.com/docs/vue/eventcalendar/api#opt-clickToCreate) - option
- [`dragToCreate`](https://mobiscroll.com/docs/vue/eventcalendar/api#opt-dragToCreate) - option
- [`dragToMove`](https://mobiscroll.com/docs/vue/eventcalendar/api#opt-dragToMove) - option
- [`dragToResize`](https://mobiscroll.com/docs/vue/eventcalendar/api#opt-dragToResize) - option
- [`eventDelete`](https://mobiscroll.com/docs/vue/eventcalendar/api#opt-eventDelete) - option
- [`view`](https://mobiscroll.com/docs/vue/eventcalendar/api#opt-view) - option
- [`data`](https://mobiscroll.com/docs/vue/eventcalendar/api#opt-data) - option
- [`resources`](https://mobiscroll.com/docs/vue/eventcalendar/api#opt-resources) - option
- [`selectedDate`](https://mobiscroll.com/docs/vue/eventcalendar/api#opt-selectedDate) - option
- [`refDate`](https://mobiscroll.com/docs/vue/eventcalendar/api#opt-refDate) - option
- [`page-loaded`](https://mobiscroll.com/docs/vue/eventcalendar/api#event-onPageLoaded) - event
- [`selected-date-change`](https://mobiscroll.com/docs/vue/eventcalendar/api#event-onSelectedDateChange) - event
- [`select`](https://mobiscroll.com/docs/vue/datepicker/api#opt-select) - option
- [`display`](https://mobiscroll.com/docs/vue/datepicker/api#opt-display) - option
- [`anchor`](https://mobiscroll.com/docs/vue/datepicker/api#opt-anchor) - option
- [`showOverlay`](https://mobiscroll.com/docs/vue/datepicker/api#opt-showOverlay) - option
- [`touchUi`](https://mobiscroll.com/docs/vue/datepicker/api#opt-touchUi) - option
- [`buttons`](https://mobiscroll.com/docs/vue/datepicker/api#opt-buttons) - option
- [`inputProps`](https://mobiscroll.com/docs/vue/datepicker/api#opt-inputProps) - option
- [`close`](https://mobiscroll.com/docs/vue/datepicker/api#event-onClose) - event
- [`change`](https://mobiscroll.com/docs/vue/datepicker/api#event-onChange) - event

## Code

### SFC JS

```vue
<script setup>
import {
  formatDate,
  getJson,
  MbscButton,
  MbscCalendarNext,
  MbscCalendarPrev,
  MbscCalendarToday,
  MbscDatepicker,
  MbscEventcalendar,
  setOptions
} from '@mobiscroll/vue'
import { onMounted, ref } from 'vue'

setOptions({
  theme: 'ios',
  themeVariant: 'light'
})

const myResources = [
  {
    id: 1,
    name: 'Resource A',
    color: '#e20000'
  },
  {
    id: 2,
    name: 'Resource B',
    color: '#76e083'
  },
  {
    id: 3,
    name: 'Resource C',
    color: '#4981d6'
  },
  {
    id: 4,
    name: 'Resource D',
    color: '#e25dd2'
  },
  {
    id: 5,
    name: 'Resource E',
    color: '#1dab2f'
  },
  {
    id: 6,
    name: 'Resource F',
    color: '#d6d145'
  }
]

const myView = ref({
  timeline: {
    type: 'day',
    size: 14,
    eventDisplay: 'fill'
  }
})

const myEvents = ref([])
const mySelectedDate = ref(new Date())
const myRefDate = ref(new Date())
const myRange = ref([])
const startDate = ref(null)
const endDate = ref(null)
const buttonText = ref('')
const pickerElm = ref(null)
const myAnchor = ref(null)

// 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
}

// 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)) : '')
  )
}

function handlePageLoaded(args) {
  const sDate = args.firstDay
  const end = args.lastDay
  const eDate = new Date(end.getFullYear(), end.getMonth(), end.getDate() - 1, 0)
  startDate.value = sDate
  endDate.value = eDate
  setTimeout(() => {
    // Set button text
    buttonText.value = getFormattedRange(sDate, eDate)
    // Set range value
    myRange.value = [sDate, eDate]
    // Navigate the calendar
    mySelectedDate.value = sDate
  })
}

function handleSelectedDateChange(args) {
  mySelectedDate.value = args.date
}

function handleChange(args) {
  const date = args.value
  myRange.value = date
  if (date[0] && date[1]) {
    startDate.value = date[0]
    endDate.value = date[1]
  }
}

function handleOpen(ev) {
  pickerElm.value.instance.open()
  myAnchor.value = ev.target
}

function handleClose() {
  if (startDate.value && endDate.value) {
    // Navigate the calendar
    mySelectedDate.value = startDate.value
    // Set calendar view
    myRefDate.value = startDate.value
    myView.value = {
      timeline: {
        type: 'day',
        size: getNrDays(startDate.value, endDate.value),
        eventDisplay: 'fill'
      }
    }
  }
  myRange.value = [startDate.value, endDate.value]
}

onMounted(() => {
  getJson(
    'https://trial.mobiscroll.com/timeline-events/',
    (events) => {
      myEvents.value = events
    },
    'jsonp'
  )
})
</script>

<template>
  <MbscEventcalendar :clickToCreate="true" :dragToCreate="true" :dragToMove="true" :dragToResize="true" :eventDelete="true"
    :view="myView"
    :data="myEvents"
    :resources="myResources"
    :selectedDate="mySelectedDate"
    :refDate="myRefDate"
    @page-loaded="handlePageLoaded"
    @selected-date-change="handleSelectedDateChange"
  >
    <template #header>
      <div>
        <MbscDatepicker
          ref="pickerElm"
          select="range"
          display="anchored"
          :anchor="myAnchor"
          :showOverlay="false"
          :touchUi="true"
          :buttons="[]"
          :inputProps="{ type: 'hidden' }"
          :value="myRange"
          @close="handleClose"
          @change="handleChange"
        />
      </div>
      <MbscButton variant="flat" className="mbsc-calendar-button" @click="handleOpen">
        {{ buttonText }}
      </MbscButton>
      <div class="md-custom-range-view-controls">
        <MbscCalendarPrev />
        <MbscCalendarToday />
        <MbscCalendarNext />
      </div>
    </template>
  </MbscEventcalendar>
</template>

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

.mbsc-material .mbsc-calendar-title {
  font-size: 1.428572em;
  font-weight: 400;
  text-transform: none;
  line-height: 1.4em;
}
</style>
```

### SFC TS

```vue
<script setup lang="ts">
import {
  formatDate,
  getJson,
  MbscButton,
  MbscCalendarNext,
  MbscCalendarPrev,
  MbscCalendarToday,
  MbscDatepicker,
  MbscEventcalendar,
  setOptions
} from '@mobiscroll/vue'
import type {
  MbscCalendarEvent,
  MbscEventcalendarView,
  MbscPageLoadedEvent,
  MbscResource,
  MbscSelectedDateChangeEvent
} from '@mobiscroll/vue'
import { onMounted, ref } from 'vue'

setOptions({
  theme: 'ios',
  themeVariant: 'light'
})

const myResources: MbscResource[] = [
  {
    id: 1,
    name: 'Resource A',
    color: '#e20000'
  },
  {
    id: 2,
    name: 'Resource B',
    color: '#76e083'
  },
  {
    id: 3,
    name: 'Resource C',
    color: '#4981d6'
  },
  {
    id: 4,
    name: 'Resource D',
    color: '#e25dd2'
  },
  {
    id: 5,
    name: 'Resource E',
    color: '#1dab2f'
  },
  {
    id: 6,
    name: 'Resource F',
    color: '#d6d145'
  }
]

const myView = ref<MbscEventcalendarView>({
  timeline: {
    type: 'day',
    size: 14,
    eventDisplay: 'fill'
  }
})

const myEvents = ref<MbscCalendarEvent[]>([])
const mySelectedDate = ref<any>(new Date())
const myRefDate = ref<any>(new Date())
const myRange = ref<any>([])
const startDate = ref<any>(null)
const endDate = ref<any>(null)
const buttonText = ref<string>('')
const pickerElm = ref<any>(null)
const myAnchor = ref<any>(null)

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

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

function handlePageLoaded(args: MbscPageLoadedEvent) {
  const sDate = args.firstDay
  const end = args.lastDay
  const eDate = new Date(end.getFullYear(), end.getMonth(), end.getDate() - 1, 0)
  startDate.value = sDate
  endDate.value = eDate
  setTimeout(() => {
    // Set button text
    buttonText.value = getFormattedRange(sDate, eDate)
    // Set range value
    myRange.value = [sDate, eDate]
    // Navigate the calendar
    mySelectedDate.value = sDate
  })
}

function handleChange(args: any) {
  const date = args.value
  myRange.value = date
  if (date[0] && date[1]) {
    startDate.value = date[0]
    endDate.value = date[1]
  }
}

function handleSelectedDateChange(args: MbscSelectedDateChangeEvent) {
  mySelectedDate.value = args.date
}

function handleOpen(ev: any) {
  pickerElm.value.instance.open()
  myAnchor.value = ev.target
}

function handleClose() {
  if (startDate.value && endDate.value) {
    // Navigate the calendar
    mySelectedDate.value = startDate.value
    // Set calendar view
    myRefDate.value = startDate.value
    myView.value = {
      timeline: {
        type: 'day',
        size: getNrDays(startDate.value, endDate.value),
        eventDisplay: 'fill'
      }
    }
  }
  myRange.value = [startDate.value, endDate.value]
}

onMounted(() => {
  getJson(
    'https://trial.mobiscroll.com/timeline-events/',
    (events: MbscCalendarEvent[]) => {
      myEvents.value = events
    },
    'jsonp'
  )
})
</script>

<template>
  <MbscEventcalendar :clickToCreate="true" :dragToCreate="true" :dragToMove="true" :dragToResize="true" :eventDelete="true"
    :view="myView"
    :data="myEvents"
    :resources="myResources"
    :selectedDate="mySelectedDate"
    :refDate="myRefDate"
    @page-loaded="handlePageLoaded"
    @selected-date-change="handleSelectedDateChange"
  >
    <template #header>
      <div>
        <MbscDatepicker
          ref="pickerElm"
          select="range"
          display="anchored"
          :anchor="myAnchor"
          :showOverlay="false"
          :touchUi="true"
          :buttons="[]"
          :inputProps="{ type: 'hidden' }"
          :value="myRange"
          @close="handleClose"
          @change="handleChange"
        />
      </div>
      <MbscButton variant="flat" className="mbsc-calendar-button" @click="handleOpen">
        {{ buttonText }}
      </MbscButton>
      <div class="md-custom-range-view-controls">
        <MbscCalendarPrev />
        <MbscCalendarToday />
        <MbscCalendarNext />
      </div>
    </template>
  </MbscEventcalendar>
</template>

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

.mbsc-material .mbsc-calendar-title {
  font-size: 1.428572em;
  font-weight: 400;
  text-transform: none;
  line-height: 1.4em;
}
</style>
```

## Implementation notes

- Start with `timeline: { type: 'day', size: 14, eventDisplay: 'fill' }` as the default view - a 14-day rolling window with events filling their cells. Store the view config in state so it can be replaced when the user picks a new range.
- Use `renderHeader` (Angular: `headerTemplate`, Vue: `#header` slot) to replace the default navigation with two elements: a `Button` that shows the current date range label and opens the range picker, and a group of `CalendarPrev`, `CalendarToday`, `CalendarNext` controls aligned to the right.
- Render a `Datepicker` in `select: 'range'`, `display: 'anchored'`, `showOverlay: false`, `touchUi: true`, `buttons: []` mode as the range picker. In React, pass it directly as `inputComponent={Button}` with `inputProps` containing the label text as children. In Vue/Angular, keep the picker hidden (hidden input or no visible input) and call `.open()` on the instance from the button's click handler, passing the button element as the anchor.
- In the Datepicker `onChange` handler, store the selected `[start, end]` pair in a ref/variable (not yet applied to the calendar - wait for close).
- In the Datepicker `onClose` handler, compute `size = getNrDays(start, end)` and update the timeline view to `{ timeline: { type: 'day', size, eventDisplay: 'fill' } }`. Also set `refDate` to the start date and update `selectedDate` to navigate the calendar to the start.
- In the `onPageLoaded` event, read `args.firstDay` as the range start. The `args.lastDay` is exclusive (one day past the last visible day), so compute the actual end as `new Date(lastDay.getFullYear(), lastDay.getMonth(), lastDay.getDate() - 1)`. Use both to update the button label text and the range picker's value - this keeps the picker in sync when the user navigates with the prev/next buttons.
- Implement a `getNrDays(start, end)` helper: `Math.round(Math.abs((end.setHours(0) - start.setHours(0)) / 86400000)) + 1`. Use `formatDate('MMM D, YYYY', date)` from Mobiscroll to build the label string; show a single date when the range spans one day, or "Start - End" for multiple days.
- Define 6 generic resources with `id`, `name`, and `color`. Load events from a remote endpoint using `getJson` and pass them to `data`.

## 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-vue.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 vue
   ```

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 vue --trial`.

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

## Related demos

- Previous: [Event Buffer Time](https://demo.mobiscroll.com/vue/timeline/event-buffer.md) - Visualize buffer time on a Vue Timeline — show travel time, check-in/out, loading/unloading time, or preparation windows around scheduled events.
- Next: [Custom Event Ordering](https://demo.mobiscroll.com/vue/timeline/custom-event-sort.md) - Set event order in Vue Timeline rows via per-event order value or a custom ordering function — useful for priority-based and dense weekly schedules.
