EventRenderer
Mixin
Mixin that provides the ability to generate DomConfig blocks for rendering event bars in Calendar views. It produces the DOM structure for event elements including the event body content, icon, color styling, and CSS class management. The mixin supports a customizable eventRenderer function that allows applications to modify the appearance and content of event bars at render time.
Views that use this mixin accept an eventRenderer config to customize event display:
const calendar = new Calendar({
modes : {
month : {
eventRenderer({ eventRecord, renderData }) {
// Add a custom CSS class based on event data
renderData.cls['my-custom-event'] = eventRecord.type === 'meeting';
renderData.style.fontWeight = eventRecord.important ? 'bold' : '';
return eventRecord.name;
}
}
}
});
Configs
Configs are options you supply in a configuration object when creating an instance of this class-
A function, or the name of a function in the ownership hierarchy which you can specify to customize event DOM content.
This function is called each time an event is rendered to produce the header DOM structure which precedes the body content (Event name).
In DayView (WeekView is a DayView), the default event header is the event's start, and/or end, and/or duration depending on the showTime setting. Times are formatted according to the timeFormat
Other views produce horizontal event bars, and do not have a separate event header element.
Default behaviour can be overridden by specifying this property.
The defaultEventHeaderRenderer returns a DomConfig object in the following form:
{ className : 'b-event-header', children : [{ className : 'b-event-time', text : '11:00' }] }An application could augment this to add a UTC time string like this:
eventHeaderRenderer({ view, eventRecord }) { const utcString = TimeZoneHelper.fromTimeZone(eventRecord.startDate, view.project.timeZone).toISOString().substring(11, 16), result = this.defaultEventHeaderRenderer(...arguments); result.children.push({ className : 'b-event-utc', text : `UTC: ${utcString}`, }); return result; }Or it could produce completely custom content, such as a flexible start time:
eventHeaderRenderer({ eventRecord }) { return [{ class : 'flexible-start', text : DateHelper.format(eventRecord.startDate, '{Around} hh:mm') }, { class : 'status-indicator fa', text : eventRecord.completed ? '\xf00c' : '\xf00d' }]; }It is passed all the same data as the eventRenderer function, so it can also affect the
renderDataobject to change the style, classes, and other properties of the main event bar element.Parameters
- detail : Object
An object that contains data about the event being rendered
- view : CalendarView
The view rendering the event
- eventRecord : EventModel
The event record
- resourceRecord : ResourceModel
The resource record
- renderData : Object
A data object containing properties that will be used to create the event element
- style : Object
The style property is an object containing style properties for the event element
- cls : Object
The cls property is an object whose property names will be added to the event element if the property value is truthy
- iconStyle : Object
The iconStyle property is an object containing style properties for the icon element if an icon element is to be used
- iconCls : Object
The iconCls property is an object whose property names will be added to the icon element. Initially set from the event record's iconCls. Can be mutated by the renderer. If null, or no properties are set, no icon will be rendered
- eventColor : String
Color to be applied to the event
- dataset : Object
An object which produces the
datasetof the resulting event bar - solidBar : Boolean
This is valid for views which create event bars. This is set to
trueby default for all day and interday events so that these appear as a solid block of background color. An eventRenderer may mutate this flag to change in what manner the event bar is colored - as a solid bar of color, or using the foreground color (text and icons) such as the MonthView, the CalendarRow (all day events in a DayView), and OverflowPopups - bodyColor : String
When used in a DayView, this color is applied to the body of the event element. Note that this must be light enough that the text color (From the SASS variable
$dayview-event-color) is visible - showBullet : Boolean
If there is no
iconCls, and the event is not recurring, then by default a "bullet" circular icon is shown if the view's showBullet if set. Setting this property in an event renderer overrides this behaviour.
Returns
- detail : Object
-
A function, or the name of a function in the ownership hierarchy which you can specify to customize event DOM content.
This function is called each time an event is rendered to allow developers to mutate the cell metadata, or the CSS classes to be applied to the event element.
It's called with the event record, and a eventData object which allows you to mutate event metadata such as
cls,style.The
clsproperty is an object whose property names will be added to the event element if the property value is truthy.The
styleproperty is an object containing style properties for the event element.A non-null return value from the renderer is used as the event body content. A nullish return value causes the default renderer to be used which just uses the event name.
If a string is returned, it is used as the HTML content of the event body element.
If an object is returned, it is used as a DomConfig object to create complex content in the event body element.
You should never modify any records inside this method.eventRenderer({ eventRecord, renderData }) { if (eventRecord.name === 'Doctors appointment') { renderData.style.fontWeight = 'bold'; renderData.cls['custom-cls'] = 1; return 'Special doctors appointment'; } }IMPORTANT: When returning content, be sure to consider how that content should be encoded to avoid XSS (Cross-Site Scripting) attacks. This is especially important when including user-controlled data such as the event's
name. The function encodeHtml as well as xss can be helpful in these cases.For example:
eventRenderer({ eventRecord }) { return StringHelper.xss`Event: ${eventRecord.name}`; }Event background and text colors
The background bar of the event may be customized by setting the
eventBackgroundproperty and the text color by setting thetextColorproperty in therenderDataobject:modes : { month : { eventRenderer({ renderData }) { // Set the background to a gradient based on the event color renderData.eventBackground = 'linear-gradient(to right, var(--b-calendar-event-color), color-mix(in srgb, var(--b-calendar-event-color), #ffffff 60%))'; // Set the text color to a contrasting CSS color renderData.textColor = 'darkolivegreen'; } } }Parameters
- context : Object
An object that contains data about the event being rendered
- view : CalendarMixin
The view rendering the event
- eventRecord : EventModel
The event record
- resourceRecord : ResourceModel
The Resource record
- renderData : Object
A data object containing properties that will be used to create the event element
- style : Object
The style property is an object containing style properties for the event element
- cls : Object
The cls property is an object whose property names will be added to the event element if the property value is truthy
- iconStyle : Object
The iconStyle property is an object containing style properties for the icon element if an icon element is to be used
- iconCls : Object
The iconCls property is an object whose property names will be added to the icon element. Initially set from the event record's iconCls. Can be mutated by the renderer. If null, or no properties are set, no icon will be rendered
- eventColor : String
Color to be applied to the event. This may be a CSS color name or a CSS color value in any of the supported CSS color formats such as
#RRGGBB,rgb(255, 0, 0), orrgba(255, 0, 0, 0.5). - eventBackground : String
A CSS background style to be applied to the event. This is not set by default, but can be set by the renderer to provide a background image or gradient for the event bar. This overrides the
eventColorproperty if present. - textColor : String
A CSS color to be applied to the event text. This is not set by default, but can be set by the renderer to provide a custom color for the event name text in the event bar. This may be a CSS color name or a CSS color value in any of the supported CSS color formats such as
#RRGGBB,rgb(255, 0, 0), orrgba(255, 0, 0, 0.5). - eventInnerStyle : Object
The eventInnerStyle property is an object containing style properties for the inner part of the event element, the
.b-cal-eventelement. - dataset : Object
An object which produces the
datasetof the resulting event bar - solidBar : Boolean
This is valid for views which create event bars. This is set to
trueby default for all day and interday events so that these appear as a solid block of background color. An eventRenderer may mutate this flag to change in what manner the event bar is colored - as a solid bar of color, or using the foreground color (text and icons) such as the MonthView, the CalendarRow (all day events in a DayView), and OverflowPopups - bodyColor : String
When used in a DayView, this color is applied to the body of the event element. Note that this must be light enough that the text color (From the SASS variable
$dayview-event-color) is visible - showBullet : Boolean
If there is no
iconCls, and the event is not recurring, then by default a "bullet" circular icon is shown if the view's showBullet if set. Setting this property in an event renderer overrides this behaviour.Using JSX (React)
When using the Bryntum React wrapper, the event renderer can return JSX elements:
eventRenderer({ eventRecord, renderData }) { return <MyEventComponent event={eventRecord} />; }Using JSX in the event renderer creates a React portal for each rendered event. For calendars with many visible events or frequently re-rendered views, this may impact scrolling performance compared to returning plain strings or DomConfig objects. Consider using JSX primarily for events that require complex interactive React components.
Returns
- context : Object
-
If this is set to
true, then when determining which assigned resource of a multi assigned event to use to create the event UI, the first resource which is still selected in the resourceFilter is used.The default is to use the first resource in the assigned list.
The resource's eventColor is used as the color for the event unless the event has its own eventColor.
The resource's eventStyle is used as the base of the style for the event, and the event's style is applied to it.
Has a corresponding runtime filterEventResources property.
-
A Function (or name of a function in the ownership hierarchy) which returns the resource record to use to create the UI for an event.
The resource's eventColor is used as the color for the event unless the event has its own eventColor.
The resource's eventStyle is used as the base of the style for the event, and the event's style is applied to it.
For views which are linked to a single resource such as
ResourceViewandDayResourceView, the default implementation always returns the view's resource.If multi assignment is used, the default is to pick the first resource in the assigned resource list.
If this view's filterEventResources is
true, then the first assigned event which is still filtered in is chosen.An implementation of this function may be configured in to your modes to customize how the resource is chosen from a multi assigned event.
Properties
Properties are getters/setters or publicly accessible variables on this class-
Identifies an object as an instance of EventRenderer class, or subclass thereof.
-
If this is set to
true, then when determining which assigned resource of a multi assigned event to use to create the event UI, the first resource which is still selected in the resourceFilter is used.The default is to use the first resource in the assigned list.
The resource's eventColor is used as the color for the event unless the event has its own eventColor.
The resource's eventStyle is used as the base of the style for the event, and the event's style is applied to it.
Has a corresponding filterEventResources config.
-
Identifies an object as an instance of EventRenderer class, or subclass thereof.
Functions
Functions are methods available for calling on the class-
Returns a CSS style value value for the passed color name.
If the name is a bryntum-defined color in the current theme, the value of that variable is returned, for example
--cal-color-red.If the name is not a bryntum-defined color, the name is returned unchanged.
-
This is the standard way to create a DomConfig element definition object for creating event bars in all view types.
This may be used by application code which needs to create DOM structure for event bars, such as in custom cell renderers in an AgendaView.
-
The default event header renderer which is used if no eventHeaderRenderer is specified.
This is used in the DayView (WeekView is a DayView), and produces a header with the event's start time, and optionally the end time, or duration if the view's showTime is set.