Event Search Popup

Use the available real estate in the calendar header to add event search. With the templating capabilities of the header you can easily add a search box and use a separate agenda instance to show the search results. This example is relying on a single API endpoint for getting the data onto the primary calendar view and also for getting the filtered data based on the search terms.

Events can be filtered in real time so using an agenda view for the search results is an easy choice. It provides all the necessary styling and advanced features that you might need to customize the experience.

Alternatively, search can be implemented in a sidebar next to the event calendar using a similar search box with an inline agenda instead of a dropdown.

Get started with this example

Demo

Loading the live demo

Preview in full screen

Search events in real time from the event calendar header — results appear in an agenda-style popup as you type, grouped by date.

Code

<script setup>
import {
  formatDate,
  getJson,
  MbscCalendarNav,
  MbscCalendarNext,
  MbscCalendarPrev,
  MbscCalendarToday,
  MbscEventcalendar,
  MbscInput,
  MbscPopup,
  setOptions 
} from '@mobiscroll/vue'
import { ref } from 'vue'

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

const calEvents = ref([])
const isPopupOpen = ref(false)
const listEvents = ref([])
const searchInput = ref(null)
const selectedEvent = ref([])

const calInst = ref(null)
const timer = ref(null)
const inputRef = ref(null)

const calView = { calendar: { labels: true } }
const listView = { agenda: { type: 'year', size: 5 } }

function handleInputChange(ev) {
  const searchText = ev.target.value

  clearTimeout(timer.value)
  timer.value = setTimeout(() => {
    if (searchText.length > 0) {
      getJson(
        'https://trial.mobiscroll.com/searchevents/?text=' + searchText,
        (data) => {
          listEvents.value = data
          isPopupOpen.value = true
        },
        'jsonp'
      )
    } else {
      isPopupOpen.value = false
    }
  }, 200)
}

function handleInputFocus(ev) {
  if (ev.target.value.length > 0) {
    isPopupOpen.value = true
  }
}

function handlePageLoading(args) {
  const start = formatDate('YYYY-MM-DD', args.viewStart)
  const end = formatDate('YYYY-MM-DD', args.viewEnd)

  setTimeout(() => {
    getJson(
      'https://trial.mobiscroll.com/searchevents/?start=' + start + '&end=' + end,
      (data) => {
        calEvents.value = data
      },
      'jsonp'
    )
  })
}

function handlePopupClose() {
  isPopupOpen.value = false
}

function handleEventClick(args) {
  selectedEvent.value = [args.event]
  isPopupOpen.value = false
  calInst.value.instance.navigateToEvent(args.event)
}

function handleInit() {
  setTimeout(() => {
    searchInput.value = inputRef.value.instance.nativeElement
  })
}
</script>

<template>
  <MbscEventcalendar
    ref="calInst"
    :clickToCreate="false"
    :data="calEvents"
    :dragToCreate="false"
    :dragToMove="false"
    :dragToResize="false"
    :selectMultipleEvents="true"
    :selectedEvents="selectedEvent"
    :view="calView"
    @init="handleInit"
    @page-loading="handlePageLoading"
  >
    <template #header>
      <MbscCalendarNav />
      <div class="mds-search-bar mbsc-flex-1-0">
        <MbscInput
          autocomplete="off"
          inputStyle="box"
          placeholder="Search events"
          startIcon="material-search"
          ref="inputRef"
          @input="handleInputChange"
          @focus="handleInputFocus"
        />
      </div>
      <MbscCalendarPrev />
      <MbscCalendarToday />
      <MbscCalendarNext />
    </template>
  </MbscEventcalendar>
  <MbscPopup
    display="anchored"
    :anchor="searchInput"
    :contentPadding="false"
    :focusElm="searchInput"
    :focusOnClose="false"
    :focusOnOpen="false"
    :isOpen="isPopupOpen"
    :scrollLock="false"
    :showArrow="false"
    :showOverlay="false"
    :width="200"
    @close="handlePopupClose"
  >
    <MbscEventcalendar
      cssClass="mds-search-results"
      :data="listEvents"
      :showControls="false"
      :view="listView"
      @event-click="handleEventClick"
    />
  </MbscPopup>
</template>

<style>
.mds-search-bar .mbsc-textfield-wrapper {
  max-width: 400px;
  margin: 8px auto;
}

.mds-search-bar .mbsc-textfield.mbsc-ios-dark {
  background: #313131;
}

.mds-search-results .mbsc-calendar-wrapper {
  margin-top: -1px;
}
</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.