Custom Range View

The scheduler comes with built-in support for day, week and month views. For those situations where a custom range makes more sense, it is possible to override the calendar navigation component with a range picker.

The calendar header can be easily customized and a two-way synchronization needs to be kept between the scheduler and range picker.

Download and try example

Demo

Loading the live demo

Preview in full screen

Configure the Scheduler with a custom date range view — let users pick any date span from a header range picker instead of fixed day.

Code

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

var formatDate = mobiscroll.formatDate;
var startDate;
var endDate;
var end;

var myCalendar = mobiscroll.eventcalendar('#demo-custom-range-view', {
  clickToCreate:  ,
  dragToCreate:  ,
  dragToMove:  ,
  dragToResize:  ,
  eventDelete:  ,
  view: {
    scheduler: {
      type: 'day',
      size: 14,
    },
  },
  renderHeader: function () {
    return (
      '<div id="custom-date-range"><button mbsc-button data-variant="flat" class="mbsc-calendar-button">' +
      '<span id="custom-date-range-text" class="mbsc-calendar-title">Button' +
      '</span></button></div>' +
      '<div class="md-custom-range-view-controls">' +
      '<div mbsc-calendar-prev></div>' +
      '<div mbsc-calendar-today></div>' +
      '<div mbsc-calendar-next></div>' +
      '</div>'
    );
  },
  onPageLoaded: function (args) {
    startDate = args.firstDay;
    end = args.lastDay;
    endDate = new Date(end.getFullYear(), end.getMonth(), end.getDate() - 1, 0);
    // Set button text
    rangeButton.innerText = getFormattedRange(startDate, endDate);
    // Set range value
    myRange.setVal([startDate, endDate]);
  },
});

var myRange = mobiscroll.datepicker('#custom-date-range', {
  select: 'range',
  display: 'anchored',
  showOverlay: false,
  touchUi: true,
  buttons: [],
  onClose: function (args, inst) {
    var date = inst.getVal();
    if (date[0] && date[1]) {
      if (date[0].getTime() !== startDate.getTime()) {
        // Navigate the calendar
        myCalendar.navigate(date[0]);
      }
      startDate = date[0];
      endDate = date[1];
      // Set calendar view
      myCalendar.setOptions({
        refDate: startDate,
        view: {
          scheduler: {
            type: 'day',
            size: getNrDays(startDate, endDate),
          },
        },
      });
    } else {
      myRange.setVal([startDate, endDate]);
    }
  },
});

var rangeButton = document.getElementById('custom-date-range-text');

// Returns the formatted date
function getFormattedRange(start, end) {
  return (
    formatDate('MMM D, YYYY', new Date(start)) +
    (end && getNrDays(start, end) > 1 ? ' - ' + formatDate('MMM D, YYYY', new Date(end)) : '')
  );
}

// Returns the number of days between two dates
function getNrDays(start, end) {
  return Math.round(Math.abs((end.setHours(0) - start.setHours(0)) / (24 * 60 * 60 * 1000))) + 1;
}

mobiscroll.getJson(
  'https://trial.mobiscroll.com/events/?vers=5',
  function (events) {
    myCalendar.setEvents(events);
  },
  'jsonp',
);
  

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.