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.
//<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
Configs
21Common
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.
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>
`;
}
}
}
});
| Parameter | Type | Description |
|---|---|---|
data | Object | Tooltip data |
data.timeRange | TimeSpan | The time range record being dragged |
data.name | String | Time range name |
data.startDate | Date | Start date |
data.endDate | Date | End date |
data.startText | String | Formatted start date string |
data.endText | String | Formatted end date string |
data.startClockHtml | String | Predefined HTML to show the start time |
data.endClockHtml | String | Predefined HTML to show the end time |
data.valid | Boolean | Whether the drag position is valid |
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.
Misc
The interval (as amount of ms) defining how frequently the current timeline will be updated
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.
true when you use a headerRenderer.Other
Properties
22
Properties
22Common
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.
Class hierarchy
Misc
Returns the Store used by this feature. This is always the owning Scheduler/Gantt's Project TimeRangeStore.
Other
Returns the TimeRanges which occur within the client Scheduler's time axis.
Functions
31
Functions
31Configuration
Events
Misc
Other
Events
9
Events
9Fires 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 }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Scheduler | The scheduler |
date | Date | The current date |
Event handlers
9
Event handlers
9Called on the owning Scheduler/Gantt when the line indicating the current time is updated (see currentTimeLineUpdateInterval).
new TimeRanges({
onCurrentTimelineUpdate({ source, date }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Scheduler | The scheduler |
date | Date | The current date |