ViewPreset
A ViewPreset is a record of PresetStore which describes the granularity of the timeline view of a Scheduler and the layout and subdivisions of the timeline header.
You can create a new instance by specifying all fields:
const myViewPreset = new ViewPreset({
id : 'myPreset', // Unique id value provided to recognize your view preset. Not required, but having it you can simply set new view preset by id: scheduler.viewPreset = 'myPreset'
name : 'My view preset', // A human-readable name provided to be used in GUI, e.i. preset picker, etc.
tickWidth : 24, // Time column width in horizontal mode
tickHeight : 50, // Time column height in vertical mode
displayDateFormat : 'HH:mm', // Controls how dates will be displayed in tooltips etc
shiftIncrement : 1, // Controls how much time to skip when calling shiftNext and shiftPrevious.
shiftUnit : 'day', // Valid values are 'millisecond', 'second', 'minute', 'hour', 'day', 'week', 'month', 'quarter', 'year'.
defaultSpan : 12, // By default, if no end date is supplied to a view it will show 12 hours
timeResolution : { // Dates will be snapped to this resolution
unit : 'minute', // Valid values are 'millisecond', 'second', 'minute', 'hour', 'day', 'week', 'month', 'quarter', 'year'.
increment : 15
},
headers : [ // This defines your header rows from top to bottom
{ // For each row you can define 'unit', 'increment', 'dateFormat', 'renderer', 'align', and 'thisObj'
unit : 'day',
dateFormat : 'ddd DD/MM'
},
{
unit : 'hour',
dateFormat : 'HH:mm'
}
],
columnLinesFor : 1 // Defines header level column lines will be drawn for. Defaults to the last level.
});
Or you can extend one of view presets registered in PresetManager:
const myViewPreset2 = new ViewPreset({
id : 'myPreset', // Unique id value provided to recognize your view preset. Not required, but having it you can simply set new view preset by id: scheduler.viewPreset = 'myPreset'
name : 'My view preset', // A human-readable name provided to be used in GUI, e.i. preset picker, etc.
base : 'hourAndDay', // Extends 'hourAndDay' view preset provided by PresetManager. You can pick out any of PresetManager's view presets: PresetManager.records
timeResolution : { // Override time resolution
unit : 'minute',
increment : 15 // Make it increment every 15 mins
},
headers : [ // Override headers
{
unit : 'day',
dateFormat : 'DD.MM.YYYY' // Use different date format for top header 01.10.2020
},
{
unit : 'hour',
dateFormat : 'LT'
}
]
});
See PresetManager for the list of base presets. You may add your own presets to this global list:
PresetManager.add(myViewPreset); // Adds new preset to the global scope. All newly created scheduler instances will have it too.
const scheduler = new Scheduler({
viewPreset : 'myPreset'
// other configs...
});
Or add them on an individual basis to Scheduler instances:
const scheduler = new Scheduler({...});
scheduler.presets.add(myViewPreset); // Adds new preset to the scheduler instance only. All newly created scheduler instances will **not** have it.
scheduler.viewPreset = 'myPreset';
Defining custom header rows
You can have any number of header rows by specifying headers, see ViewPresetHeaderRow for the config object format and DateHelper for the supported date formats, or use to render custom contents into the row cells.
headers : [
{
unit : 'month',
dateFormat : 'MM.YYYY'
},
{
unit : 'week',
renderer : ({ startDate }) => `Week ${DateHelper.format(startDate, 'WW')}`
}
]
//<code-header>
fiddle.title = 'Custom header';
CSSHelper.insertRule('.customHeader .b-sch-header-time-axis-cell { font-size:0.9em;border-left:1px solid rgb(160 160 160);border-bottom:1px solid rgb(160 160 160); font-weight:400;}', targetElement.getRootNode());
//</code-header>
new Scheduler({
appendTo : targetElement,
cls : 'customHeader',
autoHeight : true,
startDate : new Date(2022, 4, 1),
endDate : new Date(2022, 6, 1),
resources : [
{ id : 1, name : 'Bob' },
{ id : 2, name : 'John' },
{ id : 3, name : 'Kate' },
{ id : 4, name : 'Lisa' }
],
events : [
{ id : 1, resourceId : 1, startDate : new Date(2022, 4, 3), duration : 5, name : 'A cool task' }
],
viewPreset : {
timeResolution : {
unit : 'day',
increment : 1
},
headers : [
{
unit : 'month',
dateFormat : 'MMM YYYY',
align : 'start'
},
{
unit : 'week',
renderer : (startDate, endDate) => `Week ${DateHelper.format(startDate, 'WW')}`
},
{
unit : 'day',
dateFormat : 'dd'
},
{
unit : 'day',
dateFormat : 'DD'
},
{
unit : 'day',
renderer : (startDate, endDate, headerConfig, index) => index % 4 === 0 ? Math.round(Math.random() * 5) : ''
}
]
},
columns : [
{ field : 'name', text : 'Name', width : 100 }
]
});This live demo shows a custom ViewPreset with AM/PM time format:
//<code-header>
fiddle.title = 'AM/PM preset';
//</code-header>
new Scheduler({
appendTo : targetElement,
autoHeight : true,
startDate : new Date(2018, 4, 6),
endDate : new Date(2018, 4, 8),
viewPreset : {
timeResolution : {
unit : 'hour',
increment : 1
},
headers : [
{
unit : 'day',
dateFormat : 'DD MMM YYYY'
},
{
unit : 'hour',
dateFormat : 'hA'
}
]
},
columns : [
{ field : 'name', text : 'Name', width : 100 }
]
});Using embedded text inside format string
Arbitrary text can be embedded in the format string by wrapping it with {}:
headers : [
{
unit : 'month',
dateFormat : '{It is }MMMM{, yay!}' -> It is January, yay!
},
{
unit : 'week',
renderer : ({ startDate }) => `Week ${DateHelper.format(startDate, 'WW')}`
}
]
Properties
62
Properties
62Class hierarchy
Editing
JSON
Parent & children
Functions
54
Functions
54Configuration
Editing
Events
Other
Parent & children
Typedefs
3
Typedefs
3Defines a header level for a ViewPreset.
A sample header configuration can look like below
headers : {
{
unit : "month",
renderer : function(start, end, headerConfig, index) {
var month = start.getMonth();
// Simple alternating month in bold
if (start.getMonth() % 2) {
return '<strong>' + month + '</strong>';
}
return month;
},
align : 'start' // `start` or `end`, omit to center content (default)
},
{
unit : "week",
increment : 1,
renderer : function(start, end, headerConfig, index) {
return 'foo';
}
},
}
| Parameter | Type | Description |
|---|---|---|
align | start | center | end | The text alignment for the cell. Valid values are |
unit | DurationUnit | The unit of time represented by each cell in this header row. See also increment property. Valid values are "millisecond", "second", "minute", "hour", "day", "week", "month", "quarter", "year". |
headerCellCls | String | A CSS class to add to the cells in the time axis header row. Can also be added
programmatically in the |
increment | Number | The number of units each header cell will represent (e.g. 30 together with unit: "minute" for 30 minute cells) |
dateFormat | String | Defines how the cell date will be formatted |
renderer | function | A custom renderer function used to render the cell content. It should return text/HTML to put in the header cell.
The render function is called with the following parameters: |
renderer.startDate | Date | The start date of the cell. |
renderer.endDate | Date | The end date of the cell. |
renderer.headerConfig | Object | An object containing the header config. |
renderer.headerConfig.align | start | center | end | The text alignment for the cell. See |
renderer.headerConfig.headerCellCls | String | A CSS class to add to the cells in the time axis header row.
See |
renderer.index | Number | The index of the cell in the row. |
thisObj | Object |
|
cellGenerator | function | A function that should return an array of objects containing 'start', 'end' and 'header' properties. Use this if you want full control over how the header rows are generated. Note: Example : |
An object containing a unit identifier and an increment variable, used to define the timeResolution of a
ViewPreset.
| Parameter | Type | Description |
|---|---|---|
unit | String | The unit of the resolution, e.g. 'minute' |
increment | Number | The increment of the resolution, e.g. 15 |
Fields
15
Fields
15The name of an existing view preset to extend
Index of a header level in the headers array for which column lines are drawn. See ColumnLines. Defaults to the bottom header.
The amount of time to show by default in a view (in the unit defined by mainUnit)
Defines how dates will be formatted in tooltips etc
An array containing one or more ViewPresetHeaderRow config objects, each of
which defines a level of headers for the scheduler.
The main unit will be the last header's unit, but this can be changed using the
mainHeaderLevel field.
Index of the headers array to define which header level is the main header.
Defaults to the bottom header.
Initially set to a unit. Defaults to the unit defined by the middle header.
The name of the view preset
The height of the row in horizontal orientation
The amount to shift (in shiftUnits)
The unit to shift when calling shiftNext/shiftPrevious to navigate in the chart. Valid values are "millisecond", "second", "minute", "hour", "day", "week", "month", "quarter", "year".
Note: Currently, this field only applies when changing viewPreset with the ViewPresetCombo.
Set to a number and that amount of mainUnit will be added to the startDate. For example: A
start value of 5 together with the mainUnit hours will add 5 hours to the startDate. This can achieve
a "day view" that starts 5 AM.
Set to a string unit (for example week, day, month) and the startDate will be the start of that unit
calculated from current startDate. A start value of week will result in a startDate in the first day of
the week.
If set to a number or not set at all, the startDate will be calculated at the beginning of current mainUnit.
The height of the time tick column in vertical orientation
The width of the time tick column in horizontal orientation
An object containing a unit identifier and an increment variable. This value means minimal task duration you can create using UI. For example when you drag create a task or drag & drop a task, if increment is 5 and unit is 'minute' that means that you can create a 5-minute-long task, or move it 5 min forward/backward. This config maps to scheduler's timeResolution config.
timeResolution : {
unit : 'minute', //Valid values are "millisecond", "second", "minute", "hour", "day", "week", "month", "quarter", "year".
increment : 5
}