TimeSelection

Feature that allows selection of a time span in the time axis header. When a time span is selected in the header, a timeSelectionChange event is fired.

Time selection
//<code-header>
fiddle.title = 'Time selection';
//</code-header>
const scheduler = new Scheduler({
    appendTo : targetElement,

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

    features : {
        timeSelection : {
            headerRenderer({ timeRange }) {
                return `<span class="b-selection-start">${DateHelper.format(timeRange.startDate, 'LST')}</span>
                        <span class="b-selection-end">${DateHelper.format(timeRange.endDate, 'LST')}</span>
                        <i class='fa fa-close' data-ref="closeButton" data-btip="Close"></i>`;
            }
        }
    },
    viewPreset : 'hourAndDay',
    startDate  : new Date(2022, 4, 8, 8),
    endDate    : new Date(2022, 4, 8, 16),

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

    resources : [
        { id : 1, name : 'Bernard' },
        { id : 2, name : 'Bianca' },
        { id : 3, name : 'Rolf' },
        { id : 4, name : 'Bengt' },
        { id : 5, name : 'Penny' }
    ],

    events : [
        { id : 1, resourceId : 1, name : 'Interview', startDate : '2022-05-08T09:00:00', endDate : '2022-05-08T10:00:00' },
        { id : 2, resourceId : 2, name : 'Meeting', startDate : '2022-05-08T13:00:00', endDate : '2022-05-08T15:00:00' },
        { id : 3, resourceId : 3, name : 'Future task', startDate : '2022-05-08T09:00:00', endDate : '2022-05-08T11:30:00' }
    ],

    bbar : [
        {
            ref  : 'selectionLabel',
            type : 'widget'
        }
    ],

    getAvailableResources(startDate, endDate) {
        return this.resourceStore.query(resource => this.isDateRangeAvailable(startDate, endDate, null, resource));
    },

    onTimeSelectionChange({ startDate, endDate }) {
        const availableResources = startDate ? this.getAvailableResources(startDate, endDate).length : this.resourceStore.count;

        this.widgetMap.selectionLabel.html = `${availableResources} resources available`;
    }
});

scheduler.features.timeSelection.selectedTimeSpan = {
    startDate : new Date(2022, 4, 8, 10),
    endDate   : new Date(2022, 4, 8, 13)
};

Configuration

You can configure the content of the header element using the headerRenderer function.

Not compatible with the HeaderZoom feature.

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

Configs

18

Common

headerRenderer: function

Function used to generate the HTML content for the selected time span's header element.

If you want to include an icon or similar to clear the selection on click, make sure to set date-ref="closeButton" on it.

const scheduler = new Scheduler({
    features : {
        timeSelection : {
            headerRenderer({ timeRange }) {
                return `
                    ${DateHelper.format(timeRange.startDate, 'LL')}
                    <div class="close" data-ref="closeButton></div>
                `;
            }
        }
    }
});
ParameterTypeDescription
dataObject

Render data

data.timeRangeObject
data.timeRange.startDateDate
data.timeRange.endDateDate
Returns: String
tooltipTemplate: function

Template used to generate the tooltip contents when hovering the time selection header element.

const scheduler = new Scheduler({
  features : {
    timeSelection : {
      tooltipTemplate({ startDate, endDate }) {
          const count = this.client.getAvailableResources(startDate, endDate).length;
          return `${count || 'No'} available resource(s)`;
      }
    }
  }
});
ParameterTypeDescription
dataObject

Tooltip data

data.startDateDate
data.endDateDate
Returns: String -

String representing the HTML markup

bodyRendererAbstractTimeRanges
disabledInstancePlugin
enableResizingAbstractTimeRanges
hoverTooltipAbstractTimeRanges
listenersEvents
showHeaderElementsAbstractTimeRanges
showTooltipAbstractTimeRanges

Other

Specify true to enable a drag-drop gesture to select the time span.

The selected time span, which can be set using simple startDate and endDate properties

ParameterTypeDescription
selectedTimeSpan.startDateDate

The start date of the selected time span

selectedTimeSpan.endDateDate

The end date of the selected time span

Misc

clientInstancePlugin
localeClassLocalizable
localizableLocalizable

Properties

21

Common

disabledInstancePlugin
showHeaderElementsAbstractTimeRanges

Class hierarchy

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

Other

Specify true to enable a drag-drop gesture to select the time span.

The selected time span, which can be set using simple startDate and endDate properties

ParameterTypeDescription
selectedTimeSpan.startDateDate

The start date of the selected time span

selectedTimeSpan.endDateDate

The end date of the selected time span

hoverTooltipAbstractTimeRanges

Lifecycle

configBase

Misc

clientInstancePlugin
localeHelperLocalizable
localeManagerLocalizable

Functions

31

Configuration

applyDefaultsstaticBase

Events

Lifecycle

destroystaticBase

Misc

doDisableInstancePlugin
initClassstaticBase
isOfTypeNamestaticBase
mixinstaticBase
optionalLstaticLocalizable

Other

createOnFrameDelayable
getTipHtmlAbstractTimeRanges
LstaticLocalizable
onEvents
relayAllEvents
shouldRenderRangeAbstractTimeRanges
triggerEvents
unEvents

Events

10

Triggered when time selection changes

// Adding a listener using the "on" method
timeSelection.on('timeSelectionChange', ({ source, startDate, endDate }) => {

});
ParameterTypeDescription
sourceScheduler

The scheduler

startDateDate

The selected range start date, or undefined

endDateDate

The selected range end date, or undefined

Triggered when clicking the time selection header element

// Adding a listener using the "on" method
timeSelection.on('timeSelectionElementClick', ({ source, startDate, endDate, domEvent }) => {

});
ParameterTypeDescription
sourceScheduler

The scheduler

startDateDate

The selected range start date

endDateDate

The selected range end date

domEventEvent

The raw DOM event

catchAllEvents
destroyEvents
disableInstancePlugin
enableInstancePlugin
timeRangeHeaderClickAbstractTimeRanges
timeRangeHeaderContextMenuAbstractTimeRanges
timeRangeHeaderDblClickAbstractTimeRanges

Event handlers

10

Called when time selection changes

new TimeSelection({
    onTimeSelectionChange({ source, startDate, endDate }) {

    }
});
ParameterTypeDescription
sourceScheduler

The scheduler

startDateDate

The selected range start date, or undefined

endDateDate

The selected range end date, or undefined

Called when clicking the time selection header element

new TimeSelection({
    onTimeSelectionElementClick({ source, startDate, endDate, domEvent }) {

    }
});
ParameterTypeDescription
sourceScheduler

The scheduler

startDateDate

The selected range start date

endDateDate

The selected range end date

domEventEvent

The raw DOM event

onDestroyEvents
onDisableInstancePlugin
onEnableInstancePlugin
onTimeRangeHeaderClickAbstractTimeRanges
onTimeRangeHeaderDblClickAbstractTimeRanges

Typedefs

2

CSS variables

3
NameDescription
--b-time-selection-opacityTime selection body opacity
--b-time-selection-header-backgroundTime selection header background
--b-time-selection-backgroundTime selection body background color