Resource Parsing Premium

All of the techniques for specifying resources accept an array of raw objects. These raw objects are “parsed” into proper Resource objects, which are accessible via methods like getResources and getResourceById.

The following properties are accepted in each raw resource object:

idUniquely identifies this resource. Event Objects with a corresponding resourceId field will be linked to this event. Will be coerced into a string.
titleText that will be displayed on the resource when it is rendered.
eventColorEvents associated with this resources will have their backgrounds and borders colored. Any CSS string color format can be specified, like "#f00" or "rgb(255,0,0)". For how this combines with other colors, see Precedence.
eventContrastColorThe eventContrastColor setting for associated events.
eventClassCSS class name(s) that will apply to associated events.
eventEditableSets both eventStartEditable and eventDurationEditable for associated events, like the editable setting.
eventStartEditableThe eventStartEditable setting for associated events.
eventDurationEditableThe eventDurationEditable setting for associated events.
eventOverlapThe eventOverlap setting for associated events. Does not accept a function.
eventConstraintThe eventConstraint setting for associated events.
eventAllowThe eventAllow setting for associated events.
businessHoursA businessHours declaration that will only apply to this resource. See example.
childrenChild resources. See below.
parentIdDefines the parent resource. See below.
any other prop!

Every other non-standard prop will be transferred over to the extendedProps hash in the Resource object.

Resources can be nested within each other. This will be displayed as an expander arrow in the UI which expands and contracts the child resources. Specifying nested resources can be done via one of two possible techniques…

Precedence#

An event’s settings can come from four places. From lowest to highest precedence:

  1. The calendar’s options, such as eventColor
  2. The event’s event source, such as its color
  3. The event’s resource, such as its eventColor
  4. The event itself, such as its color

For eventColor, eventContrastColor, eventEditable, eventStartEditable, eventDurationEditable and eventOverlap, a higher place overrides a lower one. The others add up instead:

  • eventClass: the classes from every place are applied together.
  • eventConstraint and eventAllow: a drag or resize must satisfy each place’s constraint, and pass each place’s eventAllow.

A resource’s settings reach its events in every view, including views without resources, such as timeGridWeek.

For now, the order above holds only for how events render in views without resources. In resource views, such as resourceTimelineDay, and when checking whether a drag or resize is allowed in any view, the event source ranks above the resource:

  1. The calendar’s options
  2. The event’s resource
  3. The event’s event source
  4. The event itself

For example, an event whose source sets color: 'green' and whose resource sets eventColor: 'red' is red in timeGridWeek but green in resourceTimelineDay. A future release will make the resource rank above the source everywhere. To get the same result in every view now, set the value on the events themselves, or on only one of the source and the resource.

Nested resources with a nested array#

Child resources can be specified directly within the parent resource via the children property. This technique is often more pleasant when hardcoding an array because it is visually easier to understand the code.

resources: [
  {
    id: 'a',
    title: 'Room A',
    children: [
      {
        id: 'a1',
        title: 'Room A1'
      },
      {
        id: 'a2',
        title: 'Room A2'
      }
    ]
  }
]

Nested resources with a flat array#

An alternative method for specifying child resources is via linking them together with the parentId property. This is often more pleasant when dealing with resource data that originates from a database.

resources: [
  {
    id: 'a',
    title: 'Room A'
  },
  {
    id: 'a1',
    parentId: 'a',
    title: 'Room A1'
  },
  {
    id: 'a2',
    parentId: 'a',
    title: 'Room A2'
  }
]