v7.3.0
SupportExamplesFree Trial

EventModel

This class represent a single event in your schedule, usually added to a EventStore.

It is a subclass of the TimeSpan, which is in turn a subclass of Model. Please refer to the documentation of that class to become familiar with the base interface of the event.

Recurrence

This class mixes RecurringTimeSpan which provides recurrence support. Using the recurrenceRule and exceptionDates you can express just about any recurrence pattern. Below is the data for a repeating event happening every weekday at 10am.

{
  "id"             : 1,
  "name"           : "Daily standup",
  "startDate"      : "2024-01-03 10:00",
  "duration"       : 1,
  "durationUnit"   : "hour",
  "recurrenceRule" : "FREQ=WEEKLY;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR"
}

Async date calculations

A record created from an EventModel is normally part of an EventStore, which in turn is part of a project. When dates or the duration of an event is changed, the project performs async calculations to normalize the other fields. For example if duration is changed, it will calculate endDate.

As a result of this being an async operation, the values of other fields are not guaranteed to be up to date immediately after a change. To ensure data is up to date, await the calculations to finish.

For example, endDate is not up to date after this operation:

eventRecord.duration = 5;
// endDate not yet calculated

But if calculations are awaited it is up to date:

eventRecord.duration = 5;
await eventRecord.project.commitAsync();
// endDate is calculated

As an alternative, you can also use setAsync() to trigger calculations directly after the change:

await eventRecord.setAsync({ duration : 5});
// endDate is calculated

Subclassing the Event model class

The Event model has a few predefined fields as seen below. If you want to add new fields or change the options for the existing fields, you can do that by subclassing this class (see example below).

class MyEvent extends EventModel {

static get fields() { return [ // Add new field { name: 'myField', type : 'number', defaultValue : 0 } ]; },

myCheckMethod() { return this.myField > 0 },

... });

If you in your data want to use other names for the startDate, endDate, resourceId and name fields you can configure them as seen below:

class MyEvent extends EventModel {

static get fields() { return [ { name: 'startDate', dataSource : 'taskStart' }, { name: 'endDate', dataSource : 'taskEnd', format: 'YYYY-MM-DD' }, { name: 'resourceId', dataSource : 'userId' }, { name: 'name', dataSource : 'taskTitle' }, ]; }, ... });

Please refer to Model for additional details.

Changing default field values

Default values for fields can be changed without subclassing or redefining fields using applyDefaults. This should be called before data is loaded into stores:

// Change the default duration unit for all new events
EventModel.applyDefaults({ durationUnit : 'week' });

See also

No results

Fields

Fields belong to a Model class and define the Model data structure
  • The unique identifier of a task (mandatory)

  • The name of the time span (or Event / Task)

  • Id of the resource this event is associated with (only usable for single assignments). We recommend using assignments in an AssignmentStore over this approach. Internally any Event using resourceId will have an assignment in AssignmentStore generated.

  • Ids of the resources this event is associated with (can be used for multiple assignments). Any event using resourceIds will have assignments in AssignmentStore generated automatically. It only applies if is configured with persist: true.

      class CustomEventModel extends EventModel {
          static $name = 'CustomEventModel';
    
          static get fields() {
              return [
                  { name : 'resourceIds', persist : true }
              ];
          }
      };
    
      const
          resources   = [
              { id : 'r1', name : 'Celia' },
              { id : 'r2', name : 'Lee' },
              { id : 'r3', name : 'Macy' },
              { id : 'r4', name : 'Madison' }
          ],
          events      = [
              {
                  id          : 1,
                  resourceIds : ['r1', 'r2']
                  ...
              },
              {
                  id          : 2,
                  resourceIds : ['r3', 'r4']
                  ...
              }
          ];
    
      const scheduler = new Scheduler({
          ...
          eventStore : {
              modelClass : CustomEventModel,
              data       : events
          },
          ...
      });
    
  • The array of resources which are assigned to this event.

  • Specify false to prevent the event from being dragged (if EventDrag feature is used)

  • Specify false to prevent the event from being resized (if EventResize feature is used). You can also specify 'start' or 'end' to only allow resizing in one direction

  • A field marking event as all day(s) spanning event. For example, a holiday day may be represented by a startDate, and the allDay flag.

  • The timespan recurrence rule. A string in RFC-5545 described format ("RRULE" expression).

  • Controls the primary color of the event. For available standard colors, see EventColor.

  • eventStyle : 'plain'/'border'/'colored'/'hollow'/'line'+ 7 more
    EventModelMixin

    Controls this events appearance, see Schedulers eventStyle config for available options.

  • CSS class specifying an icon to apply to the rendered time span element. Note: In case event is a milestone, using iconCls with dependency feature might slightly decrease performance because feature will refer to the DOM to get exact size of the element.

  • Width (in px) to use for this milestone when using Scheduler#milestoneLayoutMode 'data'.

  • Set this field to false to opt out of sticky event content (keeping event text in view while scrolling).

  • A CSS style string (applied to style.cssText) or object (applied to style)

    record.style = 'color: red;font-weight: 800';
    
  • 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.

  • parentId : String/Number/null
    READONLY
    TreeNode

    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
  • isEventModel : Booleantrue
    READONLY
    static
    ADVANCED
    Identifies an object as an instance of EventModel class, or subclass thereof.
  • isEventModelMixin : Booleantrue
    READONLY
    static
    ADVANCED
    EventModelMixin
    Identifies an object as an instance of EventModelMixin class, or subclass thereof.
  • isModelStm : Booleantrue
    READONLY
    static
    ADVANCED
    ModelStm
    Identifies an object as an instance of ModelStm class, or subclass thereof.
  • isRecurringTimeSpan : Booleantrue
    READONLY
    static
    ADVANCED
    RecurringTimeSpan
    Identifies an object as an instance of RecurringTimeSpan class, or subclass thereof.
  • isTimeZonedDatesMixin : Booleantrue
    READONLY
    static
    ADVANCED
    TimeZonedDatesMixin
    Identifies an object as an instance of TimeZonedDatesMixin class, or subclass thereof.
  • isTreeNode : Booleantrue
    READONLY
    static
    ADVANCED
    TreeNode
    Identifies an object as an instance of TreeNode class, or subclass thereof.
  • properties : Object
    internal
    static
    Model

    A class property getter for the default values of internal properties for this class.

  • allFields : DataField[]
    READONLY
    static
    Model

    An array containing all the defined fields for this Model class. This will include all superclass's defined fields.

  • fieldMap : Object<String, DataField>
    READONLY
    static
    Model

    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.keys and Object.entries will only access this class's defined fields.

  • The data source for the id field which provides the ID of instances of this Model.

  • Returns all assignments for the event. Event must be part of the store for this method to work.

  • Returns the first assigned resource, or assigns a resource

  • Returns all resources assigned to an event.

  • emptyArray : Array
    internal
    READONLY
    Model

    An empty array that can be used as a default value.

  • emptyObject : Object
    internal
    READONLY
    Model

    An empty object that can be used as a default value.

  • isEventModel : Booleantrue
    READONLY
    ADVANCED
    Identifies an object as an instance of EventModel class, or subclass thereof.
  • isModel : Booleantrue
    READONLY
    ADVANCED
    Model
    Identifies an object as an instance of Model class, or subclass thereof.
  • isTimeSpan : Booleantrue
    READONLY
    ADVANCED
    TimeSpan
    Identifies an object as an instance of TimeSpan class, or subclass thereof.
  • Returns all predecessor dependencies of this event

  • Returns all successor dependencies of this event

  • copyOf : Model
    READONLY
    Model

    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.

  • Returns true if event can be drag and dropped

  • True if this model has any uncommitted changes.

  • Returns false if the event is not persistable. By default it always is, override this getter if you need custom logic.

  • isValid : Boolean
    READONLY
    Model

    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.

  • rawModificationData : Object
    internal
    READONLY
    Model

    Returns a map of the modified persistable fields

  • Override persistable getter to prevent sending resourceId when using multiple resource assignment mode https://github.com/bryntum/support/issues/1345

  • 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 undefined otherwise.

  • 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).

  • config : Object
    READONLY
    ADVANCED
    Model

    Returns a copy of the full configuration which was used to configure this object.

  • isConstructing : Boolean
    READONLY
    ADVANCED
    Model

    This property is set to true before the constructor returns.

  • isDestroying : Boolean
    READONLY
    ADVANCED
    Model

    This property is set to true on entry to the destroy method. It remains on the objects after returning from destroy(). If isDestroyed is true, this property will also be true, so there is no need to test for both (for example, comp.isDestroying || comp.isDestroyed).

  • Is this record linked to another record?

  • Get the original record this record is linked to.

  • Returns the event store this event is part of, if any.

  • Get the first store that this model is assigned to.

  • Reference to STM manager, if used

  • isRemoved : Boolean
    internal
    READONLY
    Model

    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

  • indexPath : Number[]
    private
    READONLY
    Model

    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 true if this node is the root of the tree

  • Get the last child of this node

  • Get the next sibling of this node

  • parent : Model
    READONLY
    TreeNode

    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 the WBS code of this model (e.g '2.1.3'). Only relevant when part of a tree store, as in the Gantt chart.

  • Indicates if the timespan is an occurrence of another recurring timespan.

  • Indicates if the timespan is recurring.

  • The setter used by Model#inSet when addExceptionDate is called. Adding an exception must trigger change processing in a recurring event, so it must be changed through a set call. Also, the change must be batchable with other changes.

  • The original {@lScheduler.model.TimeSpan#field-startDate startDate} of this event before any modifications took place. Used by removeOccurrence and detachFromRecurringEvent

  • If this event is an occurrence of a recurring event, then this property yields its zero-based occurrence index in the sequence.

  • occurrenceMap : Map
    internal
    READONLY
    RecurringTimeSpan

    A Map, keyed by each date an occurrence intersects, of occurrences of this event.

  • The recurrence model used for the timespan.

  • Name of the class representing the recurrence model, defaults to RecurrenceModel

  • The "main" timespan this model is an occurrence of. For non-occurrences returns null.

  • Returns true if this timespan supports recurring.

  • dates : Date[]
    READONLY
    TimeSpan

    Returns an array of dates in this range. If the range starts/ends not at the beginning of day, the whole day will be included.

  • Returns the duration of this Event in milliseconds.

  • Returns true if record is a milestone.

  • Checks if the range record has both start and end dates set and start <= end

  • Returns the event raw duration in milliseconds. Calculated as a simple distance between the event start and end dates in milliseconds. And thus this value (in Scheduler Pro and Gantt) doesn't take into account non-working time nor the project conversion rates.

  • 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
  • onClassMixedIn( )
    internal
    static
    Model

    This optional class method is called when a class is mixed in using the mixin() method.

  • initClass( )
    static
    ADVANCED
    Model

    Registers this class type with its Factory

  • exposeRelations( )
    internal
    static
    Model

    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.

  • Iterate over all associated resources

  • 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

  • Detaches an occurrence from its owning recurring event so that it can be added to the eventStore either as an exception, or as the start of a new recurring sequence.

  • The method is triggered when the timespan recurrence settings get changed. It updates the recurrenceRule field in this case.

  • Override of Model's method. If an isOccurrence is passed, it is detached from its parent recurring event. If it still has a recurrence then the recurring event is changed to stop at the occurrence date. If it has no recurrence an exception is added at the occurrence date.

  • Removes this recurring timespan's cached occurrences.

  • Removes all cached occurrences on or after the passed date from this recurring timespan's cached occurrences.

  • initRelations( )
    private
    Model

    Initializes model relations. Called from store when adding a record.

  • clear( )
    private
    TreeNode

    Removes all records from the rootNode

Source path

Scheduler/model/EventModel.js

Contents