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 onResourceExpand lifecycle event to load the data runtime. You can learn about lifecycle events and places where to drop logic to customize the experience.

Download and try 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

mobiscroll.setOptions({
  locale:  ,
  theme: ' ',
  themeVariant: ' '
});

$(function () {
  var myResources = [
    {
      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',
    },
  ];

  var myEvents = [
    {
      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,
    },
  ];

  function loadChildResources(args) {
    var newResources = myResources.slice();
    var resource = args.resourceObj;

    if (!resource.loaded) {
      var newEvents = myEvents.slice();

      $.getJSON('https://trial.mobiscroll.com/load-resources/?res=' + args.resource + '&callback=?', function (data) {
        newEvents = $.merge(newEvents, data.events);

        myEvents = newEvents;
        resource.children = data.resources;
        resource.loaded = true;

        myCalendar.setOptions({
          data: newEvents,
          resources: newResources,
        });

        mobiscroll.toast({
          message: 'Resources loaded',
        });
      });
    }
  }

  var myCalendar = $('#demo')
    .mobiscroll()
    .eventcalendar({
      clickToCreate:  ,
      dragToCreate:  ,
      dragToMove:  ,
      dragToResize:  ,
      eventDelete:  ,
      view: {
        timeline: {
          type: 'day',
        },
      },
      resources: myResources,
      data: myEvents,
      onResourceExpand: function (args) {
        loadChildResources(args);
      },
    })
    .mobiscroll('getInst');
});
  

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.