Load Resources on Demand

The resources can be populated on initialization or in case of a bigger hierarchy, the more efficient way is to load the child resources and their events on demand.

Getting the resources and the events in real time as the user navigates improves load performance.

Use the resource-expand lifecycle event to load the data runtime. You can learn about lifecycle events and places where to drop logic to customize the experience.

Get started with this example

Demo

Loading the live demo

Preview in full screen

Build hierarchical resource scheduling interfaces with on-demand data loading — the Timeline fetches child resources.

Code

<script setup>
import {
  getJson,
  MbscEventcalendar,
  MbscToast,
  setOptions 
} from '@mobiscroll/vue'
import { ref } from 'vue'

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

const toastMessage = ref('')
const isToastOpen = ref(false)

const myEvents = ref([
  {
    start: '2026-10-25T10:00',
    end: '2026-10-25T13:00',
    title: 'Event 14',
    resource: 6
  },
  {
    start: '2026-10-25T15:00',
    end: '2026-10-25T17:30',
    title: 'Event 15',
    resource: 7
  },
  {
    start: '2026-10-25T09:00',
    end: '2026-10-25T11:00',
    title: 'Event 16',
    resource: 8
  },
  {
    start: '2026-10-25T17:00',
    end: '2026-10-25T20:00',
    title: 'Event 17',
    resource: 9
  }
])

const myResources = ref([
  {
    id: 1,
    name: 'Group 1',
    collapsed: true,
    eventCreation: false,
    children: [
      {
        id: 11,
        color: '#e20000',
        name: 'Resource 1'
      },
      {
        id: 12,
        color: '#76e083',
        name: 'Resource 2'
      },
      {
        id: 13,
        color: '#4981d6',
        name: 'Resource 3'
      }
    ]
  },
  {
    id: 2,
    name: 'Group 2',
    collapsed: true,
    eventCreation: false,
    children: [
      {
        id: 21,
        name: 'Loading...'
      }
    ]
  },
  {
    id: 3,
    name: 'Group 3',
    collapsed: true,
    eventCreation: false,
    children: [
      {
        id: 31,
        name: 'Loading...'
      }
    ]
  },
  {
    id: 4,
    name: 'Group 4',
    collapsed: true,
    eventCreation: false,
    children: [
      {
        id: 41,
        name: 'Loading...'
      }
    ]
  },
  {
    id: 5,
    name: 'Group 5',
    collapsed: true,
    eventCreation: false,
    children: [
      {
        id: 51,
        color: '#af0000',
        name: 'Resource 12'
      },
      {
        id: 52,
        color: '#446f1c',
        name: 'Resource 13'
      },
      {
        id: 53,
        color: '#1dab2f',
        name: 'Resource 14'
      }
    ]
  },
  {
    id: 6,
    name: 'Resource 17',
    color: '#167593'
  },
  {
    id: 7,
    name: 'Resource 18',
    color: '#93166c'
  },
  {
    id: 8,
    name: 'Resource 19',
    color: '#e5e923'
  },
  {
    id: 9,
    name: 'Resource 20',
    color: '#935028'
  }
])

const myView = {
  timeline: {
    type: 'day'
  }
}

function loadChildResources(args) {
  const resource = args.resourceObj

  if (!resource.loaded) {
    getJson(
      'https://trial.mobiscroll.com/load-resources/?res=' + args.resource,
      (data) => {
        const newEvents = [...myEvents.value, ...data.events]

        resource.children = data.resources
        resource.loaded = true

        myEvents.value = newEvents
        myResources.value = [...myResources.value]

        toastMessage.value = 'Resources loaded'
        isToastOpen.value = true
      },
      'jsonp'
    )
  }
}

function handleToastClose() {
  isToastOpen.value = false
}
</script>

<template>
  <MbscEventcalendar :clickToCreate="" :dragToCreate="" :dragToMove="" :dragToResize="" :eventDelete=""
    className="md-load-resources-on-demand"
    :view="myView"
    :data="myEvents"
    :resources="myResources"
    @resource-expand="loadChildResources"
  />
  <MbscToast :message="toastMessage" :isOpen="isToastOpen" @close="handleToastClose" />
</template>

<style>
.md-load-resources-on-demand .mbsc-timeline-parent {
  height: 34px;
}
</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.