Switch Between Calendar and Scheduler Views

Dynamically switch views within one instance. Use a UI control to let users do the switching or do it programmatically.

The example features a month view with events as labels, a weekly schedule view, a daily schedule and a weekly agenda. Use property binding and when the value of the property changes the settings propagate.

Get started with this example

Demo

Loading the live demo

Preview in full screen

Let users switch between month, week, day, and agenda views within a single event calendar — via header control or programmatically.

Code

<script setup>
import {
  getJson,
  MbscCalendarNav,
  MbscCalendarNext,
  MbscCalendarPrev,
  MbscCalendarToday,
  MbscEventcalendar,
  MbscSegmented,
  MbscSegmentedGroup,
  setOptions 
} from '@mobiscroll/vue'
import { onMounted, ref } from 'vue'

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

const myEvents = ref([])
const view = ref('month')
const myView = ref({
  calendar: {
    labels: true
  }
})

function changeView() {
  let calView

  switch (view.value) {
    case 'year':
      calView = {
        calendar: { type: 'year' }
      }
      break
    case 'month':
      calView = {
        calendar: { labels: true }
      }
      break
    case 'week':
      calView = {
        scheduler: { type: 'week' }
      }
      break
    case 'day':
      calView = {
        scheduler: { type: 'day' }
      }
      break
    case 'agenda':
      calView = {
        calendar: { type: 'week' },
        agenda: { type: 'week' }
      }
      break
  }

  myView.value = calView
}

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

<template>
  <MbscEventcalendar
    className="md-switching-view-cont"
    :view="myView"
    :data="myEvents"
    :height="750"
  >
    <template #header>
      <MbscCalendarNav className="cal-header-nav" />
      <div className="cal-header-picker">
        <MbscSegmentedGroup v-model="view" @change="changeView">
          <MbscSegmented value="year"> Year </MbscSegmented>
          <MbscSegmented value="month"> Month </MbscSegmented>
          <MbscSegmented value="week"> Week </MbscSegmented>
          <MbscSegmented value="day"> Day </MbscSegmented>
          <MbscSegmented value="agenda"> Agenda </MbscSegmented>
        </MbscSegmentedGroup>
      </div>
      <MbscCalendarPrev className="cal-header-prev" />
      <MbscCalendarToday className="cal-header-today" />
      <MbscCalendarNext className="cal-header-next" />
    </template>
  </MbscEventcalendar>
</template>

<style>
.md-switching-view-cont .mbsc-segmented {
  max-width: 350px;
  margin: 0 auto;
}

.md-switching-view-cont .mbsc-calendar-grid-item {
  height: 490px;
  box-sizing: border-box;
}

.cal-header-picker {
  flex: 1 0 auto;
}

.cal-header-nav {
  width: 200px;
}

/* material header order */

.mbsc-material.cal-header-prev {
  order: 1;
}

.mbsc-material.cal-header-next {
  order: 2;
}

.mbsc-material.cal-header-nav {
  order: 3;
}

.mbsc-material .cal-header-picker {
  order: 4;
}

.mbsc-material .cal-header-today {
  order: 5;
}

/* windows header order */

.mbsc-windows.cal-header-nav {
  order: 1;
}

.mbsc-windows.cal-header-prev {
  order: 2;
}

.mbsc-windows.cal-header-next {
  order: 3;
}

.mbsc-windows .cal-header-picker {
  order: 4;
}

.mbsc-windows .cal-header-today {
  order: 5;
}
</style>

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.