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> 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:
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')}`
}
]
Useful configs and functions
| Member | Description |
|---|---|
| base | Base preset to extend from |
| tickWidth | Width of each time tick in pixels |
| rowHeight | Default row height in pixels |
| displayDateFormat | Date format string for tooltips |
| headers | Array of header row configurations |
| timeResolution | Resolution for snapping and rounding |
| shiftUnit | Unit used when shifting the time axis |
See also
- PresetStore - Store holding view presets
- PresetManager - Built-in presets
- ViewPresetCombo - Combo for selecting presets
Fields
Fields belong to a Model class and define the Model data structure-
The 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
mainunit 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
mainheader. 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".
-
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 } -
Set to
falseto exclude this preset from the smooth zooming algorithm. This means that when zooming in or out in a Scheduler configured withsmoothZoom : true, the view will not switch to this preset. -
Start expanded or not (only valid for tree data)
-
This is a read-only field provided in server synchronization packets to specify which position the node takes in the parent's ordered children array. This index is set on load and gets updated on reordering nodes in tree. Sorting and filtering have no effect on it.
-
This is a read-only field provided in server synchronization packets to specify which record id is the parent of the record.
-
This is a read-only field provided in server synchronization packets to specify which position the node takes in the parent's children array. This index is set on load and gets updated automatically after row reordering, sorting, etc. To save the order, need to persist the field on the server and when data is fetched to be loaded, need to sort by this field.
-
Deprecated:
This field has been deprecated. Please read the guide to find out if your app needs to use the new isFullyLoaded field.
This field is added to the class at runtime when the Store is configured with lazyLoad. The number specified should reflect the total amount of children of a parent node, including nested descendants.
Properties
Properties are getters/setters or publicly accessible variables on this class-
Identifies an object as an instance of ModelLink class, or subclass thereof.
-
Identifies an object as an instance of ModelStm class, or subclass thereof.
-
Identifies an object as an instance of TreeNode class, or subclass thereof.
-
Identifies an object as an instance of ViewPreset class, or subclass thereof.
-
A class property getter for the default values of internal properties for this class.
-
An array containing all the defined fields for this Model class. This will include all superclass's defined fields.
-
An object containing all the defined fields for this Model class. This will include all superclass's defined fields through its prototype chain. So be aware that
Object.keysandObject.entrieswill only access this class's defined fields. -
The data source for the id field which provides the ID of instances of this Model.
-
An empty array that can be used as a default value.
-
An empty object that can be used as a default value.
-
Identifies an object as an instance of Model class, or subclass thereof.
-
Identifies an object as an instance of ViewPreset class, or subclass thereof.
-
For copied records, this property links to the original model instance from which it was copied.
-
True if this Model is currently batching its changes.
-
True if this models changes are currently being committed.
-
True if this model has any uncommitted changes.
-
Check if record has valid data. Default implementation returns true, override in your model to do actual validation.
-
Get a map of the modified fields in form of an object. The field´s dataSource is used as the property name in the returned object. The record's id is included unless its persist config is
false. -
Get a map of the modified data fields along with any alwaysWrite fields, in form of an object. The field´s dataSource is used as the property name in the returned object. Used internally by AjaxStore / CrudManager when sending updates.
-
Returns data for allpersistable fields in form of an object, using dataSource if present.
-
Returns a map of the modified persistable fields
-
Returns the string value for display purposes of an instance of this Model class. Needs to be overridden in subclasses.
-
When called on a group header row returns list of records in that group. Returns
undefinedotherwise. -
Returns true for a group header record
-
Gets the records internalId. It is assigned during creation, guaranteed to be globally unique among models.
-
Returns true if the record is new and has not been persisted (and received a proper id).
-
Returns a copy of the full configuration which was used to configure this object.
-
This property is set to
truebefore theconstructorreturns. -
This property is set to
trueon entry to the destroy method. It remains on the objects after returning fromdestroy(). If isDestroyed istrue, this property will also betrue, so there is no need to test for both (for example,comp.isDestroying || comp.isDestroyed). -
Are other records linked to this record?
-
Is this record linked to another record?
-
Get the original record this record is linked to.
-
Get links to this record.
-
Get the first store that this model is assigned to.
-
Reference to STM manager, if used
-
This yields
trueif this record is eligible for syncing with the server. It can yieldfalseif the record is in the middle of a batched update, or if it is a tentative record yet to be confirmed as a new addition. -
Returns true if this record is not part of any store.
-
Retrieve all children, excluding filtered out nodes (by traversing sub nodes)
-
Retrieve all children, including filtered out nodes (by traversing sub nodes)
-
Depth in the tree at which this node exists. First visual level of nodes are at level 0, their direct children at level 1 and so on.
-
Count all children (including sub-children) for a node (in its `firstStore´)
-
Get the first child of this node
-
Returns index path to this node. This is the index of each node in the node path starting from the topmost parent. (only relevant when its part of a tree store).
-
Is a leaf node in a tree structure?
-
Returns true for parent nodes with children loaded (there might still be no children)
-
Is a parent node in a tree structure?
-
Returns
trueif this node is the root of the tree -
Get the last child of this node
-
Get the next sibling of this node
-
This is a read-only property providing access to the parent node.
-
Get the previous sibling of this node
-
Returns count of all preceding sibling nodes (including their children).
-
Array of tree nodes without any filter applied. On first filter, will take order from sorted
children, but is not thereafter kept in sorted order, so order should not be relied upon. -
Count visible (expanded) children (including sub-children) for a node (in its
firstStore) -
Returns values of the persistable tree-defining fields: parentId, orderedParentIndex, and parentIndex or sparseIndex. parentIndex is omitted when sparseIndex is used.
Functions
Functions are methods available for calling on the class-
This optional class method is called when a class is mixed in using the mixin() method.
-
Registers this class type with its Factory
-
Makes getters and setters for related records. Populates a Model#relation array with the relations, to allow it to be modified later when assigning stores.
-
cancelBatch( ) Model
Cancels current batch operation. Any changes during the batch are discarded.
-
Reverts changes in this back to their original values.
-
Called from insertChild to notify StateTrackingManager about children insertion. Provides it with all necessary context information collected in beforeInsertChild required to undo/redo the action.
-
Called from removeChild to notify StateTrackingManager about children removing. Provides it with all necessary context information collected in beforeRemoveChild required to undo/redo the action.
-
Called during creation to also turn any children into Models joined to the same stores as this model
-
Initializes model relations. Called from store when adding a record.
-
Removes all records from the rootNode