Vue Agenda Bulk Actions

Multiple event selection can be turned on with the selectMultipleEvents option. Selecting multiple events can be done through user interaction with CTRL/SHIFT/CMD + click or programmatically eg. click of a button or 'select all' checkbox.

Bulk operations like delete, update can be applied the selected events. Things like deleting with the backspace or delete buttons work out of the box but custom actions can be also applied. The selection can be easily retrieved and updated with the selectedEvents option and the selected-events-change event.

Custom actions can be performed with external buttons or with context menu activated on right-click.

Get started with this example

Demo

Loading the live demo

Preview in full screen

Select multiple events in the agenda view with keyboard shortcuts or programmatically — bulk delete or update, or right-click for per-event edits.

Code

<script setup>
import {
  formatDate,
  getJson,
  MbscButton,
  MbscConfirm,
  MbscEventcalendar,
  MbscPage,
  MbscSelect,
  MbscToast,
  setOptions 
} from '@mobiscroll/vue'
import { onMounted, ref } from 'vue'

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

const calRef = ref()
const confirmMessage = ref()
const menuAction = ref()
const menuAnchor = ref()
const menuOpen = ref()
const myEvents = ref([])
const isConfirmOpen = ref()
const isToastOpen = ref()
const selectedEvent = ref()
const selectedEvents = ref([])
const toastMessage = ref()

const myView = { agenda: { type: 'month' } }

const menuData = [
  { text: 'Update', value: 'update' },
  { text: 'Delete', value: 'delete' }
]

function updateSelectedEvents() {
  const updatedEvents = [...myEvents.value]
  const events =
    selectedEvents.value.length === 0 && selectedEvent.value
      ? [selectedEvent.value]
      : selectedEvents.value
  for (const event of events) {
    const index = updatedEvents.findIndex((x) => x.id === event.id)
    // Handle recurring event occurrence
    if (event.recurring) {
      // Create a new event, with updated color and id
      const newEvent = {
        ...event,
        color: 'orange',
        id: event.id + '_' + formatDate('YYYY-MM-DD', event.start),
        recurring: undefined
      }
      // Update the original event with a recurring exception
      const updatedEvent = event.original
      const updatedExceptionDates = updatedEvent.recurringException || []
      updatedExceptionDates.push(event.start)
      updatedEvent.recurringException = updatedExceptionDates
      updatedEvents.splice(index, 1, updatedEvent)
      updatedEvents.push(newEvent)
    } else {
      // Update the event color
      const updatedEvent = { ...event, color: 'orange' }
      updatedEvents.splice(index, 1, updatedEvent)
    }
  }
  myEvents.value = updatedEvents
  selectedEvents.value = []
  toastMessage.value = "All selected event's color changed to orange"
  isToastOpen.value = true
}

function deleteSelectedEvents() {
  const events =
    selectedEvents.value.length === 0 && selectedEvent.value
      ? [selectedEvent.value]
      : selectedEvents.value
  confirmMessage.value = events.map((e) => e.title).join(', ')
  isConfirmOpen.value = true
}

function selectAllEvents() {
  selectedEvents.value = calRef.value.instance.getEvents()
  toastMessage.value = 'All events selected from view'
  isToastOpen.value = true
}

function resetSelection() {
  selectedEvents.value = []
  toastMessage.value = 'Selection cleared'
  isToastOpen.value = true
}

function handleConfirmClose(result) {
  if (result) {
    const events =
      selectedEvents.value.length === 0 && selectedEvent.value
        ? [selectedEvent.value]
        : selectedEvents.value
    const updatedEvents = [...myEvents.value]
    for (const event of events) {
      const index = updatedEvents.findIndex((x) => x.id === event.id)
      // Handle recurring event occurrence
      if (event.recurring) {
        // Update the original event with a recurring exception
        const updatedEvent = event.original
        const updatedExceptionDates = updatedEvent.recurringException || []
        updatedExceptionDates.push(event.start)
        updatedEvent.recurringException = updatedExceptionDates
        updatedEvents.splice(index, 1, updatedEvent)
      } else {
        // Remove the event
        updatedEvents.splice(index, 1)
      }
    }

    myEvents.value = updatedEvents
    selectedEvents.value = []
    toastMessage.value = 'Deleted'
    isToastOpen.value = true
  }
  isConfirmOpen.value = false
}

function handleEventUpdate(args) {
  if (args.isDelete) {
    if (!isConfirmOpen.value) {
      deleteSelectedEvents()
    }
    return false
  }
}

function handleEventDelete() {
  if (!isConfirmOpen.value) {
    deleteSelectedEvents()
    return false
  }
}

function handleEventRightClick(args) {
  args.domEvent.preventDefault()
  selectedEvent.value = args.event
  menuAnchor.value = args.domEvent.target
  menuOpen.value = true
}

function handleSelectedEventsChange(args) {
  selectedEvents.value = args.events
}

function handleMenuChange(args) {
  menuAction.value = args.value
  if (args.value === 'update') {
    updateSelectedEvents()
  } else if (args.value === 'delete') {
    deleteSelectedEvents()
  }
}

function handleMenuClose() {
  menuAction.value = ''
  menuOpen.value = false
}

function handleDeleteKey(ev) {
  if (
    !isConfirmOpen.value &&
    (ev.code === 'Delete' || ev.code === 'Backspace' || ev.keyCode === 8 || ev.keyCode === 46)
  ) {
    deleteSelectedEvents()
  }
}

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

<template>
  <MbscPage cssClass="mds-bulk-actions" @keydown="handleDeleteKey">
    <div class="mbsc-grid mbsc-no-padding">
      <div class="mbsc-row">
        <div class="mds-bulk-actions-calendar mbsc-col-sm-9 mbsc-push-sm-3">
          <MbscEventcalendar
            ref="calRef"
            :data="myEvents"
            :view="myView"
            :selectMultipleEvents="true"
            :selectedEvents="selectedEvents"
            @event-delete="handleEventDelete"
            @event-update="handleEventUpdate"
            @event-right-click="handleEventRightClick"
            @selected-events-change="handleSelectedEventsChange"
          />
          <MbscSelect
            display="anchored"
            :anchor="menuAnchor"
            :data="menuData"
            :isOpen="menuOpen"
            :showInput="false"
            :touchUi="false"
            :value="menuAction"
            @change="handleMenuChange"
            @close="handleMenuClose"
          />
        </div>
        <div class="mbsc-col-sm-3 mbsc-pull-sm-9 mbsc-flex-col">
          <div class="mbsc-button-group-block">
            <MbscButton @click="selectAllEvents">Select all from view</MbscButton>
            <MbscButton @click="resetSelection">Reset selection</MbscButton>
            <MbscButton @click="updateSelectedEvents">Update selected</MbscButton>
          </div>
          <div class="mbsc-form-group-title">Currently selected</div>
          <div class="mds-bulk-actions-event-list mbsc-padding mbsc-flex-1-1">
            <ul>
              <li v-for="event in selectedEvents" :key="event.id">{{ event.title }}</li>
            </ul>
          </div>
        </div>
      </div>
    </div>
    <MbscConfirm
      okText="Delete"
      title="Are you sure you want to delete the following events?"
      :isOpen="isConfirmOpen"
      :message="confirmMessage"
      @close="handleConfirmClose"
    />
    <MbscToast :message="toastMessage" :isOpen="isToastOpen" @close="isToastOpen = false" />
  </MbscPage>
</template>

<style>
.mds-bulk-actions,
.mds-bulk-actions .mbsc-grid,
.mds-bulk-actions .mbsc-row,
.mds-bulk-actions .mbsc-col-sm-9,
.mds-bulk-actions .mbsc-col-sm-3 {
  height: 100%;
}

.mds-bulk-actions-calendar {
  border-left: 1px solid #ccc;
}

.mds-bulk-actions-event-list {
  overflow: auto;
  padding-top: 0;
  padding-bottom: 0;
}
</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.