TimeRanges

Feature that renders global ranges of time in the timeline. Use this feature to visualize a range like a 1 hr lunch or some important point in time (a line, i.e. a range with 0 duration). This feature can also show a current time indicator if you set showCurrentTimeLine to true. To style the rendered elements, use the cls field of the TimeSpan class.

Time ranges
//<code-header>
fiddle.title = 'Time ranges';
//</code-header>
targetElement.innerHTML = '<p>This demo shows how to add a TimeRange and how to display a current time line:</p>';
const first             = DateHelper.startOf(new Date(), 'week'),
    scheduler         = new Scheduler({
        appendTo : targetElement,

        // makes scheduler as high as it needs to be to fit rows
        autoHeight : true,

        features : {
            timeRanges : {
                showCurrentTimeLine : true,
                showHeaderElements  : true,
                enableResizing      : true
            }
        },

        startDate : first,
        endDate   : DateHelper.add(first, 7, 'days'),

        columns : [
            { field : 'name', text : 'Name', width : 100 }
        ],

        resources : [
            { id : 1, name : 'Bernard' },
            { id : 2, name : 'Bianca' }
        ],

        events : [
            {
                id           : 1,
                resourceId   : 1,
                name         : 'Interview',
                startDate    : first,
                duration     : 2,
                durationUnit : 'day'
            },
            {
                id           : 2,
                resourceId   : 1,
                name         : 'Press meeting',
                startDate    : DateHelper.add(first, 4, 'days', true),
                duration     : 2,
                durationUnit : 'day'
            },
            {
                id           : 3,
                resourceId   : 2,
                name         : 'Audition',
                startDate    : DateHelper.add(first, 1, 'days'),
                duration     : 2,
                durationUnit : 'day'
            },
            {
                id           : 4,
                resourceId   : 2,
                name         : 'Script deadline',
                startDate    : DateHelper.add(first, 5, 'days'),
                duration     : 2,
                durationUnit : 'day'
            }
        ],

        timeRanges : [
            { id : 1, name : 'Cool range', startDate : DateHelper.add(first, 2, 'days'), duration : 1, durationUnit : 'day' }
        ]
    });

Each time range is represented by an instances of TimeSpan, held in a simple Store. The feature uses timeRangeStore defined on the project by default. The store's persisting/loading is handled by Crud Manager (if it's used by the component).

Note that the feature uses virtualized rendering, only the currently visible ranges are available in the DOM.

This feature is disabled by default. For info on enabling it, see GridFeatures.

Showing an icon in the time range header

You can use Font Awesome icons easily (or set any other icon using CSS) by using the iconCls field. The JSON data below will show a flag icon:

{
    "id"        : 5,
    "iconCls"   : "fa fa-flag",
    "name"      : "v5.0",
    "startDate" : "2019-02-07 15:45"
},

Recurring time ranges

The feature supports recurring ranges in case the provided store and models have RecurringTimeSpansMixin and RecurringTimeSpan mixins applied:

// We want to use recurring time ranges, so we make a special model extending standard TimeSpan model with
// RecurringTimeSpan which adds recurrence support
class MyTimeRange extends RecurringTimeSpan(TimeSpan) {}

// Define a new store extending standard Store with RecurringTimeSpansMixin mixin to add recurrence support to the
// store. This store will contain time ranges.
class MyTimeRangeStore extends RecurringTimeSpansMixin(Store) {
    static configurable = {
        // use our new MyResourceTimeRange model
        modelClass : MyTimeRange
    }
};

// Instantiate store for timeRanges using our new classes
const timeRangeStore = new MyTimeRangeStore({
    data : [{
        id             : 1,
        resourceId     : 'r1',
        startDate      : '2019-01-01T11:00',
        endDate        : '2019-01-01T13:00',
        name           : 'Lunch',
        // this time range should repeat every day
        recurrenceRule : 'FREQ=DAILY'
    }]
});

const scheduler = new Scheduler({
    ...
    features : {
        timeRanges : true
    },

    crudManager : {
        // store for "timeRanges" feature
        timeRangeStore
    }
});

Configs

21

Common

currentDateFormat: String= HH:mm

The date format to show in the header for the current time line (when showCurrentTimeLine is configured). See DateHelper for the possible formats to use.

dragTipTemplate: function

Template function used to generate the HTML for the drag tooltip that displays when dragging a time range. Override this to customize the drag tooltip content.

const scheduler = new Scheduler({
  features : {
    timeRanges : {
      dragTipTemplate({ timeRange, startText, endText, valid }) {
        return `
          <div class="my-drag-tip ${valid ? 'valid' : 'invalid'}">
            <div>Range: ${timeRange.name}</div>
            <div>Start: ${startText}</div>
            ${endText ? `<div>End: ${endText}</div>` : ''}
          </div>
        `;
      }
    }
  }
});
ParameterTypeDescription
dataObject

Tooltip data

data.timeRangeTimeSpan

The time range record being dragged

data.nameString

Time range name

data.startDateDate

Start date

data.endDateDate

End date

data.startTextString

Formatted start date string

data.endTextString

Formatted end date string

data.startClockHtmlString

Predefined HTML to show the start time

data.endClockHtmlString

Predefined HTML to show the end time

data.validBoolean

Whether the drag position is valid

Returns: String -

String representing the HTML markup

Show a line indicating current time. Either true or false or a TimeSpan configuration object to apply to this special time range (allowing you to provide a custom text):

showCurrentTimeLine : {
    name : 'Now'
}

The line carries the CSS class name b-sch-current-time, and this may be used to add custom styling to it.

bodyRendererAbstractTimeRanges
disabledInstancePlugin
enableResizingAbstractTimeRanges
headerRendererAbstractTimeRanges
hoverTooltipAbstractTimeRanges
listenersEvents
showHeaderElementsAbstractTimeRanges
showTooltipAbstractTimeRanges
tooltipTemplateAbstractTimeRanges

Misc

The interval (as amount of ms) defining how frequently the current timeline will be updated

instantUpdate: Boolean

Set to true to update the TimeRange header contents as well as the underlying record data while dragging it. In this case the record will be batch-updated during drag operations, you can listen for updates using the batchUpdate event fired by the time range store.

This flag is automatically set to true when you use a headerRenderer.

clientInstancePlugin
localeClassLocalizable
localizableLocalizable

Other

Properties

22

Common

Show a line indicating current time. Either true or false or a TimeSpan configuration object to apply to this special time range (allowing you to provide a custom text):

showCurrentTimeLine : {
    name : 'Now'
}

The line carries the CSS class name b-sch-current-time, and this may be used to add custom styling to it.

disabledInstancePlugin
showHeaderElementsAbstractTimeRanges

Class hierarchy

isTimeRanges: Boolean= truereadonly
Identifies an object as an instance of TimeRanges class, or subclass thereof.
isTimeRanges: Boolean= truereadonlystatic
Identifies an object as an instance of TimeRanges class, or subclass thereof.
isAbstractTimeRangesAbstractTimeRanges
isDelayableDelayable
isEventsEvents
isInstancePluginInstancePlugin
isLocalizableLocalizable

Misc

store: Storereadonly

Returns the Store used by this feature. This is always the owning Scheduler/Gantt's Project TimeRangeStore.

clientInstancePlugin
localeHelperLocalizable
localeManagerLocalizable

Other

Returns the TimeRanges which occur within the client Scheduler's time axis.

hoverTooltipAbstractTimeRanges

Lifecycle

configBase

Functions

31

Configuration

applyDefaultsstaticBase

Events

Lifecycle

destroystaticBase

Misc

doDisableInstancePlugin
initClassstaticBase
isOfTypeNamestaticBase
mixinstaticBase
optionalLstaticLocalizable

Other

createOnFrameDelayable
getTipHtmlAbstractTimeRanges
LstaticLocalizable
onEvents
relayAllEvents
shouldRenderRangeAbstractTimeRanges
triggerEvents
unEvents

Events

9

Fires on the owning Scheduler/Gantt when the line indicating the current time is updated (see currentTimeLineUpdateInterval).

// Adding a listener using the "on" method
timeRanges.on('currentTimelineUpdate', ({ source, date }) => {

});
ParameterTypeDescription
sourceScheduler

The scheduler

dateDate

The current date

catchAllEvents
destroyEvents
disableInstancePlugin
enableInstancePlugin
timeRangeHeaderClickAbstractTimeRanges
timeRangeHeaderContextMenuAbstractTimeRanges
timeRangeHeaderDblClickAbstractTimeRanges

Event handlers

9

Called on the owning Scheduler/Gantt when the line indicating the current time is updated (see currentTimeLineUpdateInterval).

new TimeRanges({
    onCurrentTimelineUpdate({ source, date }) {

    }
});
ParameterTypeDescription
sourceScheduler

The scheduler

dateDate

The current date

onDestroyEvents
onDisableInstancePlugin
onEnableInstancePlugin
onTimeRangeHeaderClickAbstractTimeRanges
onTimeRangeHeaderDblClickAbstractTimeRanges

Typedefs

2

CSS variables

26
NameDescription
--b-time-range-range-zindexTime range z-index
--b-time-range-line-zindexTime line z-index
--b-time-range-header-gapGap inside time range headers
--b-time-range-header-font-sizeTime range header font size
--b-time-range-header-font-weightTime range header font weight
--b-time-range-label-offsetTime range label offset from the line
--b-time-range-label-font-sizeTime range label font size
--b-time-range-opacityTime range opacity
--b-time-range-line-header-border-radiusTime range line header border radius
--b-time-range-line-header-padding-inlineTime range line header padding inline
--b-time-range-line-widthTime range line width
--b-time-range-line-styleTime range line style
--b-time-range-line-opacityTime range line opacity
--b-time-range-line-label-border-radiusTime range line label border radius
--b-time-range-line-label-paddingTime range line label padding
--b-time-range-line-label-font-sizeTime range line label font size
--b-time-range-line-label-offsetTime range line label offset
--b-time-range-colorTime range color
--b-time-range-backgroundTime range background color
--b-time-range-line-primaryTime range lines primary color
--b-time-range-line-label-colorTime range line label color
--b-current-time-colorCurrent time background & line color
--b-time-range-header-backgroundTime range header background
--b-time-range-line-colorTime range line color
--b-time-range-line-header-backgroundTime range line header background color
--b-time-range-line-label-backgroundTime range line label background color