Quarter and Year View

Create a calendar with quarter views that can be navigated quarter by quarter or switch to a year view on the fly. Show any relevant information with labels or add background colors to days along with week counters.

Get started with this example

Demo

Loading the live demo

Preview in full screen

Code

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

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

const viewType = ref('q4')
const calType = ref('month')
const selectedDate = ref(new Date())
const activeDate = ref(new Date())

function changeView() {
  const year = activeDate.value.getFullYear()
  let date
  switch (viewType.value) {
    case 'q1':
      calType.value = 'month'
      date = new Date(year, 1, 1)
      break
    case 'q2':
      calType.value = 'month'
      date = new Date(year, 4, 1)
      break
    case 'q3':
      calType.value = 'month'
      date = new Date(year, 7, 1)
      break
    case 'q4':
      calType.value = 'month'
      date = new Date(year, 10, 1)
      break
    case 'year':
      calType.value = 'year'
      date = new Date(year, selectedDate.value.getMonth(), 1)
      break
  }
  selectedDate.value = date
  activeDate.value = date
}

function handlePageChange(args) {
  let type = ''
  if (calType.value === 'year') {
    type = 'year'
  } else {
    const month = args.firstDay.getMonth()
    if (month < 3) {
      type = 'q1'
    } else if (month < 6) {
      type = 'q2'
    } else if (month < 9) {
      type = 'q3'
    } else {
      type = 'q4'
    }
  }
  viewType.value = type
  activeDate.value = args.firstDay
}
</script>

<template>
  <MbscDatepicker
    v-model="selectedDate"
    display="inline"
    :controls="['calendar']"
    :calendarSize="3"
    :calendarType="calType"
    refDate="1970-01-01"
    :showWeekNumbers="true"
    @page-change="handlePageChange"
  >
    <template #header>
      <MbscCalendarNav />
      <div class="quarter-year-header-picker">
        <MbscSegmentedGroup v-model="viewType" @change="changeView">
          <MbscSegmented value="q1">Q1</MbscSegmented>
          <MbscSegmented value="q2">Q2</MbscSegmented>
          <MbscSegmented value="q3">Q3</MbscSegmented>
          <MbscSegmented value="q4">Q4</MbscSegmented>
          <MbscSegmented value="year">Year</MbscSegmented>
        </MbscSegmentedGroup>
      </div>
      <MbscCalendarPrev />
      <MbscCalendarNext />
    </template>
  </MbscDatepicker>
</template>

<style>
.mbsc-datepicker .quarter-year-header-picker .mbsc-segmented {
  max-width: 280px;
  margin: 0 auto;
}

.quarter-year-header-picker {
  flex: 1 0 auto;
}
</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.