Resource Drag-and-Drop Reorder

Resources can be reordered directly through the UI by enabling resourceReorder: true under the timeline settings of the view option. When enabled, a drag handle icon will appear next to each resource, allowing users to drag and reorder resources.

When a resource is dropped into a new position, the onResourceOrderUpdate lifecycle event is triggered. To prevent the resource order from being updated, return false in the handler function of this event.

Use the immutableData option to ensure the original data remains unchanged when validating resource positions after a drop.

Download and try example

Demo

Loading the live demo

Preview in full screen

Reorder resources on a Timeline by drag and drop — each row shows a drag handle, and an update callback runs on drop.

Code

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

var resources = [
  { id: 1, name: 'Resource 1' },
  { id: 2, name: 'Resource 2 (Reorder disabled)', reorder: false },
  { id: 3, name: 'Resource 3' },
  { id: 4, name: 'Resource 4 (Reorder disabled)', reorder: false },
  {
    id: 5,
    name: 'Group 1',
    children: [
      { id: 6, name: 'Resource 5' },
      { id: 7, name: 'Resource 6' },
      { id: 8, name: 'Resource 7' },
    ],
  },
  { id: 9, name: 'Resource 8' },
  { id: 10, name: 'Resource 9' },
  {
    id: 11,
    name: 'Group 2',
    children: [
      { id: 12, name: 'Resource 10' },
      { id: 13, name: 'Resource 11' },
      { id: 14, name: 'Resource 12' },
    ],
  },
  { id: 15, name: 'Resource 13' },
  { id: 16, name: 'Resource 14' },
  {
    id: 17,
    name: 'Group 3',
    children: [
      { id: 18, name: 'Resource 15' },
      { id: 19, name: 'Resource 16' },
      { id: 20, name: 'Resource 17' },
    ],
  },
  { id: 21, name: 'Resource 18' },
  {
    id: 22,
    name: 'Group 4',
    children: [
      { id: 23, name: 'Resource 19' },
      { id: 24, name: 'Resource 20' },
      { id: 25, name: 'Resource 21' },
    ],
  },
  { id: 26, name: 'Resource 22' },
];
var events = [
  { id: 1, title: 'Event 1', start: '2026-10-01T00:00', end: '2026-10-05T00:00', resource: 14, color: 'green' },
  { id: 2, title: 'Event 2', start: '2026-10-03T00:00', end: '2026-10-07T00:00', resource: 2, color: 'blue' },
  { id: 3, title: 'Event 3', start: '2026-10-05T00:00', end: '2026-10-10T00:00', resource: 10, color: 'red' },
  { id: 4, title: 'Event 4', start: '2026-10-07T00:00', end: '2026-10-11T00:00', resource: 9, color: 'yellow' },
  { id: 5, title: 'Event 5', start: '2026-10-09T00:00', end: '2026-10-12T00:00', resource: 6, color: 'purple' },
];
var tempResources = [];
var calInst = mobiscroll.eventcalendar('#demo-resource-drag-drop-reorder', {
  cssClass: 'mds-resource-drag-drop-reorder',
  view: {
    timeline: {
      type: 'month',
      resolutionHorizontal: 'day',
      resourceReorder: false,
    },
  },
  immutableData: true,
  data: events,
  resources: resources,
  onEventCreate: function (args, inst) {
    events.push(args.event);
    inst.setEvents(events.slice());
  },
  onEventDelete: function (args, inst) {
    events = events.filter(function (item) {
      return item.id !== args.event.id;
    });
    inst.setEvents(events);
  },
  onEventUpdate: function (args, inst) {
    var newEvent = args.event;
    var eventIndex = events.findIndex(function (e) {
      return e.id === newEvent.id;
    });
    var newEventList = events.slice();
    newEventList.splice(eventIndex, 1, newEvent);
    events = newEventList.slice();
    inst.setEvents(newEventList);
  },
  onResourceOrderUpdate: function (args) {
    tempResources = args.resources;
  },
  renderHeader: function () {
    return (
      '<div mbsc-calendar-nav></div>' +
      '<div class="mds-reorder-header-filter mbsc-flex mbsc-flex-1-1">' +
      '<button mbsc-button data-variant="flat" class="mds-reorder-switch mds-enable">Reorder resources</button>' +
      '<button mbsc-button class="mds-reorder-save mds-update">Save</button>' +
      '<button mbsc-button class="mds-reorder-cancel mds-update">Cancel</button>' +
      '<div class="mds-reorder-header-filter-separator"></div>' +
      '<button mbsc-calendar-prev class="mds-header-filter-prev"></button>' +
      '<button mbsc-calendar-today class="mds-header-filter-today"></button>' +
      '<button mbsc-calendar-next class="mds-header-filter-next"></button>'
    );
  },
});

function updateHeaderBtns(enableOrder) {
  var enableElm = document.querySelector('.mds-enable');
  var updateElm = document.querySelectorAll('.mds-update');
  if (enableOrder) {
    enableElm.style.display = 'none';
    updateElm.forEach(function (el) {
      el.style.display = '';
    });
  } else {
    enableElm.style.display = '';
    updateElm.forEach(function (el) {
      el.style.display = 'none';
    });
  }
}

document.querySelector('.mds-reorder-switch').addEventListener(
  'click',
  function () {
    updateHeaderBtns(true);
    calInst.setOptions({
      view: {
        timeline: {
          type: 'month',
          resourceReorder: true,
        },
      },
    });
  },
  true,
);

document.querySelector('.mds-reorder-cancel').addEventListener(
  'click',
  function () {
    updateHeaderBtns(false);
    calInst.setOptions({
      resources: resources.slice(),
      view: {
        timeline: {
          type: 'month',
          resourceReorder: false,
        },
      },
    });

    mobiscroll.toast({
      message: 'Resource order canceled',
    });
  },
  true,
);

document.querySelector('.mds-reorder-save').addEventListener('click', function () {
  if (tempResources.length) {
    resources = tempResources;
  }
  updateHeaderBtns(false);
  calInst.setOptions({
    resources: resources.slice(),
    view: {
      timeline: {
        type: 'month',
        resourceReorder: false,
      },
    },
  });

  mobiscroll.toast({
    message: 'Resource order saved',
  });
});

updateHeaderBtns(false);
  

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.