MonthView
This is normally used as a mode of a Calendar (as seen in the live demo below) but may be used standalone as a regular Widget.
In the example below, the MonthView may be resized vertically by dragging the splitter handle just below it.
When the height is changed by dragging the splitter, the view responsively adjusts the event height to show more or fewer events per cell. See responsiveEventHeight.
//<code-header>
fiddle.title = 'Calendar month view';
targetElement.style.flexDirection = 'column';
//</code-header>
const calendar = new Calendar({
appendTo : targetElement,
height : 705,
minHeight : 555,
maxHeight : 730,
date : new Date(2020, 8, 1),
modes : {
month : {
// When the visible event bar count gets down to 3, then when the row height
// shrinks, start reducing the event height, stop at a minimum of 14px
responsiveEventHeight : {
threshold : 3,
minHeight : 14
},
// In our app, all events are solid blocks.
eventRenderer({ renderData }) {
renderData.solidBar = true;
}
},
day : null,
week : null,
year : null,
agenda : null
},
events : [
// 2nd has multiple events
{ startDate : '2020-09-02T07:00', duration : 1, durationUnit : 'h', name : 'Walk the dog', eventColor : 'yellow' },
{ startDate : '2020-09-02T09:00', duration : 2, durationUnit : 'h', name : 'Team sync', eventColor : 'blue' },
{ startDate : '2020-09-02T13:00', duration : 1, durationUnit : 'h', name : 'Lunch with Sam', eventColor : 'green' },
// 5th has >=3 events
{ startDate : '2020-09-05T08:00', duration : 2, durationUnit : 'h', name : 'Grocery run', eventColor : 'indigo' },
{ startDate : '2020-09-05T11:00', duration : 1, durationUnit : 'h', name : 'Yoga class', eventColor : 'lime' },
{ startDate : '2020-09-05T15:00', duration : 3, durationUnit : 'h', name : 'Project work', eventColor : 'purple' },
// 10th retains original + extra
{ startDate : '2020-09-10T09:00', duration : 2, durationUnit : 'h', name : 'Buy masks', eventColor : 'orange' },
{ startDate : '2020-09-10T12:30', duration : 1, durationUnit : 'h', name : 'One-on-one', eventColor : 'teal' },
{ startDate : '2020-09-10T16:00', duration : 1, durationUnit : 'h', name : 'Review PRs', eventColor : 'cyan' },
// 14th retains original + extras
{ startDate : '2020-09-14T07:00', duration : 1, durationUnit : 'h', name : 'Zoom meeting', eventColor : 'deep-orange' },
{ startDate : '2020-09-14T10:00', duration : 2, durationUnit : 'h', name : 'Spec drafting', eventColor : 'amber' },
{ startDate : '2020-09-14T14:00', duration : 1, durationUnit : 'h', name : 'Coffee catchup', eventColor : 'pink' },
// 18th new cluster
{ startDate : '2020-09-18T08:00', duration : 1, durationUnit : 'h', name : 'Morning run', eventColor : 'yellow' },
{ startDate : '2020-09-18T09:30', duration : 1, durationUnit : 'h', name : 'Product demo', eventColor : 'red' },
{ startDate : '2020-09-18T13:00', duration : 2, durationUnit : 'h', name : 'Architecture review', eventColor : 'deep-purple' },
// 22nd
{ startDate : '2020-09-22T09:00', duration : 3, durationUnit : 'h', name : 'Focus block', eventColor : 'gray' },
{ startDate : '2020-09-22T13:30', duration : 1, durationUnit : 'h', name : 'Client call', eventColor : 'blue' },
{ startDate : '2020-09-22T16:00', duration : 1, durationUnit : 'h', name : 'Wrap up notes', eventColor : 'green' },
// 25th retains original + extras
{ startDate : '2020-09-25T09:00', duration : 1, durationUnit : 'h', name : 'Get a haircut', eventColor : 'gray' },
{ startDate : '2020-09-25T11:00', duration : 1, durationUnit : 'h', name : 'Study time', eventColor : 'blue' },
{ startDate : '2020-09-25T14:00', duration : 2, durationUnit : 'h', name : 'Write blog post', eventColor : 'indigo' }
],
tbar : {
items : {
info : {
type : 'widget',
html : `Event height: 20px`
}
}
},
onEventHeightChange({ height, oldHeight }) {
this.widgetMap.info.html = `Event height: ${height}px`;
}
});
// Make the Calendar height-resizable
new Splitter({
appendTo : targetElement,
orientation : 'horizontal',
minWidth : '100%',
minHeight : '0.5em'
});
targetElement.appendChild(document.createElement('div'));
targetElement.lastChild.style.maxHeight = '0px';As a standalone widget, it will lack the capabilities of the Calendar class, such as keyboard-based event to event navigation and drag/drop features. As seen in this demo:
//<code-header>
fiddle.title = 'Month view';
//</code-header>
new MonthView({
appendTo : targetElement,
height : 500,
width : '100%',
title : 'September 2020',
date : new Date(2020, 8, 1),
events : [
{ startDate : '2020-09-02T07:00', duration : 5, durationUnit : 'h', name : 'Walk the dog', eventColor : 'yellow' },
{ startDate : '2020-09-10T09:00', duration : 2, durationUnit : 'h', name : 'Buy masks', eventColor : 'orange' },
{ startDate : '2020-09-14T07:00', duration : 1, durationUnit : 'h', name : 'Zoom meeting', eventColor : 'deep-orange' },
{ startDate : '2020-09-25T09:00', duration : 1, durationUnit : 'h', name : 'Get a haircut', eventColor : 'gray' }
]
});A Panel which displays a single month in a calendar like view.
Cell rendering can be customized using the dayCellRenderer method.
Event rendering can be customized using the eventRenderer method.
Configs
180
Configs
180Common
Other
By default, weeks rows all flex to share the available height equally.
To make them shrinkwrap their events to show all events in every row, configure this as true
The height of event bars in this view. This can be a numeric value in pixels or a CSS unit measure such
as '2em'.
The maximum number of events to show in a cell when the row is shrinkwrapped. Use this to keep rows to a sane size when using autoRowHeight, or the WeekExpander feature.
By default, week rows flex to share available Panel height equally.
This may be configured as a number, in which case it means pixels, or a CSS length.
The non-standard unit ev may also be specified to mean "events". For example
'3ev' means rows will always be three events bars (plus the day header)
tall.
This is a useful config when using autoRowHeight, or using overflowClickAction when rows may be switched to shrinkwrapping their event content and may shrink in height.
Setting this config causes the month grid to become scrollable in the Y axis.
How the view responds to clicking on a +n more button in an overflowing day cell.
The default value, 'popup', means that a small dialog box showing the full complement
of events for that cell is shown aligned to the cell.
When set to 'expand', then clicking the +n more button causes the encapsulating
row to expand to accommodate all events in that row with no overflow.
Navigating to a new month resets the row to its default, flexed height.
By default, rows which have been modified by the WeekExpander feature, not by the autoRowHeight setting, to shinkwrap large content are reset to flexed height on month change.
To have rows persist their shrinkwrapped status across month changes, confgure this as true.
If autoRowHeight is set, then the new month always has auto heighted rows.
An object which describes how the event bar height in month cells should respond to changes in available vertical space.
The object keys may be
- threshold : The minimum number of event bars which should be visible in a cell before the event bar height starts to be reduced.
- minHeight : The minimum event bar height to use when the threshold is reached.
When the number of event bars visible in a cell (based on the current row height) hits the threshold, from then on, further reductions in row height will cause the event bar height to be reduced, but never less than the configured minHeight.
new Calendar({
...,
modes : {
month : {
// When the visible event bar count gets down to 3, then when the row height
// shrinks, start reducing the event height, stop at a minimum of 14px
responsiveEventHeight : {
threshold : 3,
minHeight : 14
}
}
}
});
This may also be configured as an object whose keys are breakpoint heights (in pixels) and whose values are the corresponding event heights to use when the height of the event container in a cell is less than the breakpoint.
This allows events to use a larger height when more vertical space is available, and a smaller height when space is constrained:
new Calendar({
...,
modes : {
month : {
// When the event container height is less than 58px, use 16px event height
// When the event container height is less than 75px, use 18px event height
// Otherwise, use the configured eventHeight (the default is 20px)
responsiveEventHeight : {
58 : 16,
75 : 18
}
}
}
});
| Parameter | Type | Description |
|---|---|---|
threshold | Number | The minimum number of event bars which should be visible in a cell before the event bar height starts to be reduced. |
minHeight | Number | The minimum event bar height to use when the threshold is reached. |
Configure as false to hide the week number shown at the top-left of each day cell
Content
CSS
DOM
Float & align
Layout
misc
Misc
Scrolling
Properties
143
Properties
143Class hierarchy
Other
By default, weeks rows all flex to share the available height equally.
To make them shrinkwrap their events to show all events in every row, configure this as true
The height of event bars in this view. This can be a numeric value in pixels or a CSS unit measure such
as '2em'.
By default, rows which have been modified by the WeekExpander feature, not by the autoRowHeight setting, to shinkwrap large content are reset to flexed height on month change.
To have rows persist their shrinkwrapped status across month changes, confgure this as true.
If autoRowHeight is set, then the new month always has auto heighted rows.
Returns the resource associated with this month view when used inside a ResourceView
Configure as false to hide the week number shown at the top-left of each day cell
CSS
DOM
Layout
Misc
State
Widget hierarchy
Functions
95
Functions
95Other
Determines what is under the cursor of the specified event or what is described by the given element.
| Parameter | Type | Description |
|---|---|---|
domEvent | Event | Element | The event or element |
Causes the week row referenced by the parameter (Either a Date, or the zero-based row index) to become flexed in height to share the available height of the Calendar equally with other flexed rows.
See shrinkwrapWeekRow for the converse operation.
| Parameter | Type | Description |
|---|---|---|
date | Date | Number | Either the date of a day within the week, or the zero based week row to flex. |
Causes the week row referenced by the parameter (Either a Date, or the zero based row index) to size itself to exactly wrap the maximum number of events for any day of that week.
If there are a lot of events, the row may grow in height. If few, or none, the row will shrink in height. The day name header along the top will always be visible by default.
The row has the CSS class 'b-shrinkwrapped' added when it is in the shrinkwrapped state
to allow querying, and custom styling.
See flexWeekRow for the converse operation.
| Parameter | Type | Description |
|---|---|---|
week | Date | Number | Either the date of a day within the week, or the zero based week row to shrinkwrap. |
Configuration
Events
Misc
Widget hierarchy
Events
41
Events
41This event is fired when the event height changes due to resizing of the view and the application of responsiveEventHeight.
// Adding a listener using the "on" method
monthView.on('eventHeightChange', ({ height, oldHeight }) => {
});| Parameter | Type | Description |
|---|---|---|
height | Number | The new event height. |
oldHeight | Number | The previous event height. |
This event is fired as soon as a week row is requested to be flexed. The animated transition to the new height will still be in progress, but the row's flex style is set to its evenly shared flex value.
To wait until the animated transition is finished, use the Promise returned from flexWeekRow
monthView.flexWeekRow(0).then() => Toast.show('Row zero flexed);
// Adding a listener using the "on" method
monthView.on('weekFlex', ({ weekStart, element }) => {
});| Parameter | Type | Description |
|---|---|---|
weekStart | Date | The start date of the week being reverted to a flexed height. |
element | HTMLElement | The week row being reverted to a flexed height. |
This event is fired as soon as a week row is requested to be shrinkwrapped.
It's not called if we are just re-synching the height of shrinkwrapped rows which needs to be done if the shape of the data changes.
The animated transition to the new height will still be in progress, but the row's flex style is set to its calculated height.
To wait until the animated transition is finished, use the Promise returned from shrinkwrapWeekRow
monthView.shrinkwrapWeekRow(0).then() => Toast.show('Row zero shrinkwraps event content);
// Adding a listener using the "on" method
monthView.on('weekShrinkwrap', ({ weekStart, element }) => {
});| Parameter | Type | Description |
|---|---|---|
weekStart | Date | The start date of the week being shrinkwrapped. |
element | HTMLElement | The week row being shrinkwrapped. |
Event handlers
41
Event handlers
41This event is called when the event height changes due to resizing of the view and the application of responsiveEventHeight.
new MonthView({
onEventHeightChange({ height, oldHeight }) {
}
});| Parameter | Type | Description |
|---|---|---|
height | Number | The new event height. |
oldHeight | Number | The previous event height. |
This event is called as soon as a week row is requested to be flexed. The animated transition to the new height will still be in progress, but the row's flex style is set to its evenly shared flex value.
To wait until the animated transition is finished, use the Promise returned from flexWeekRow
monthView.flexWeekRow(0).then() => Toast.show('Row zero flexed);
new MonthView({
onWeekFlex({ weekStart, element }) {
}
});| Parameter | Type | Description |
|---|---|---|
weekStart | Date | The start date of the week being reverted to a flexed height. |
element | HTMLElement | The week row being reverted to a flexed height. |
This event is called as soon as a week row is requested to be shrinkwrapped.
It's not called if we are just re-synching the height of shrinkwrapped rows which needs to be done if the shape of the data changes.
The animated transition to the new height will still be in progress, but the row's flex style is set to its calculated height.
To wait until the animated transition is finished, use the Promise returned from shrinkwrapWeekRow
monthView.shrinkwrapWeekRow(0).then() => Toast.show('Row zero shrinkwraps event content);
new MonthView({
onWeekShrinkwrap({ weekStart, element }) {
}
});| Parameter | Type | Description |
|---|---|---|
weekStart | Date | The start date of the week being shrinkwrapped. |
element | HTMLElement | The week row being shrinkwrapped. |