
| Demo | |
|---|---|
| Downloads | |
| Languages | JavaScript |
Features
-
The parent rows of the JavaScript Scheduler component are used to display availability of child resources.
-
The parent row shows the number of available resources for each time slot.
-
The availability is also highlighted using color bars.
-
Includes a trial version of DayPilot Pro for JavaScript (see License below)
License
Licensed for testing and evaluation purposes. Please see the license agreement included in the sample project. You can use the source code of the tutorial if you are a licensed user of DayPilot Pro for JavaScript.
Running the Sample
Install the dependencies with npm ci and start the development server with npm run dev. Open the local URL printed by Vite. To create a production build, run npm run build.
The Scheduler configuration is in src/app.js; index.html provides the page shell and event styles. The sample uses April 2026 so the same bookings and availability are visible each time you open it. Changes stay in memory until you reload the page.
You can also try the JavaScript Scheduler group availability demo.
Calculating Availability of Child Resources in the JavaScript Scheduler
We will use the onBeforeCellRender event to customize the content of the parent row cells. For each daily time slot, we will calculate how many child resources are available:
onBeforeCellRender: (args) => {
if (args.cell.isParent) {
const row = dp.rows.find(args.cell.resource);
const children = row.children();
const total = children.length;
const used = children.filter(row => row.events.forRange(args.cell.start, args.cell.end).length > 0).length;
const available = total - used;
// ...
}
}
This event handler finds all child resources for each parent node and looks for events. If an event overlaps a particular cell, the resource is considered unavailable.
The forRange() call checks for any overlap with the cell interval. Each child contributes at most one to used, even if it has several overlapping events. Subtracting this count from total gives the number of available resources. To display a plain count, assign it to args.cell.html; the following sections place the count in an active area and add color bars.
Updating the Calculated Availability Automatically
The Scheduler only redraws the cells if it is necessary. By default, it also caches the onBeforeCellRender results to improve performance.
In order to force a refresh of the cells in the parent rows, we need to add cellsAutoUpdated: true to the parent nodes:
const resources = [
{
name: "Group 1", id: "G1", expanded: true, cellsAutoUpdated: true, children: [
{ name: "Resource 1", id: "R1" },
{ name: "Resource 2", id: "R2" }
]
},
{
name: "Group 2", id: "G2", expanded: true, cellsAutoUpdated: true, children: [
{ name: "Resource 3", id: "R3" },
{ name: "Resource 4", id: "R4" },
{ name: "Resource 5", id: "R5" }
]
},
];
This ensures that the calculations in parent row cells are updated automatically when events are added, moved, or resized. For example, moving a booking to another resource updates the affected group summaries without a full page reload. The sample also sets treePreventParentUsage: true so users create bookings on the child resources, leaving the parent rows available for summaries.
Styling the Parent Cells with Group Availability
Let's add some styling now. Instead of displaying the number as plain text, we will display it using an active area. This will let us set the font and center the text horizontally in the cell. The text property supplies the count, while horizontalAlignment controls its placement.
onBeforeCellRender: (args) => {
if (args.cell.isParent) {
const row = dp.rows.find(args.cell.resource);
const children = row.children();
const total = children.length;
const used = children.filter(row => row.events.forRange(args.cell.start, args.cell.end).length > 0).length;
const available = total - used;
// ...
args.cell.areas = [];
args.cell.areas.push({
text: `${available}`,
horizontalAlignment: "center",
style: "font-size: 12px; font-weight: bold",
top: 4,
left: 0,
right: 0
});
// ...
}
}
Highlighting the Group Availability using Color Bars
In order to make the summary easier to read, we will use active areas to add color bars that highlight the child resource availability.
We will use a light-green bar to indicate an available resource, a dark-green bar to indicate an unavailable resource, and orange bars to indicate that there are no available resources.
Each segment represents one child resource. The bars show how many resources are occupied, rather than identifying individual resources. Dividing the cell width by the number of children gives equal-width segments; subtracting one pixel leaves a small gap between them.
onBeforeCellRender: (args) => {
if (args.cell.isParent) {
const row = dp.rows.find(args.cell.resource);
const children = row.children();
const total = children.length;
const used = children.filter(row => row.events.forRange(args.cell.start, args.cell.end).length > 0).length;
const available = total - used;
const w = dp.cellWidth / total;
args.cell.areas = [];
args.cell.areas.push({
text: `${available}`,
horizontalAlignment: "center",
style: "font-size: 12px; font-weight: bold",
top: 4,
left: 0,
right: 0
});
args.cell.backColor = "#d9ead3";
if (available === 0) {
args.cell.backColor = "#f9cb9c";
}
DayPilot.list.for(total).forEach((item, i) => {
let color = "#b6d7a8";
if (i < used) {
color = "#6aa84f";
}
if (available === 0) {
color = "#e69138";
}
args.cell.areas.push({
bottom: 0,
height: 10,
left: i * w,
width: w - 1,
backColor: color
});
});
}
}
Full Source Code
Here is the complete src/app.js module. It imports DayPilot from the npm dependency and configures the Scheduler to display group availability. The page shell loads this module and can be generated using DayPilot UI Builder.
import {DayPilot} from "daypilot-pro-javascript";
const dp = new DayPilot.Scheduler("dp", {
timeHeaders: [
{groupBy:"Month"},
{groupBy:"Day", format:"d"}
],
scale: "Day",
days: 30,
startDate: "2026-04-01",
treeEnabled: true,
treePreventParentUsage: true,
rowMarginBottom: 5,
rowMarginTop: 5,
durationBarVisible: false,
onTimeRangeSelected: async (args) => {
const modal = await DayPilot.Modal.prompt("Create a new event:", "Event 1");
dp.clearSelection();
if (modal.canceled) {
return;
}
dp.events.add({
start: args.start,
end: args.end,
id: DayPilot.guid(),
resource: args.resource,
text: modal.result
});
},
onBeforeCellRender: (args) => {
if (args.cell.isParent) {
const row = dp.rows.find(args.cell.resource);
const children = row.children();
const total = children.length;
const used = children.filter(row => row.events.forRange(args.cell.start, args.cell.end).length > 0).length;
const available = total - used;
const w = dp.cellWidth / total;
args.cell.areas = [];
args.cell.areas.push({
text: `${available}`,
horizontalAlignment: "center",
style: "font-size: 12px; font-weight: bold",
top: 4,
left: 0,
right: 0
});
args.cell.backColor = "#d9ead3";
if (available === 0) {
args.cell.backColor = "#f9cb9c";
}
DayPilot.list.for(total).forEach((item, i) => {
let color = "#b6d7a8";
if (i < used) {
color = "#6aa84f";
}
if (available === 0) {
color = "#e69138";
}
args.cell.areas.push({
bottom: 0,
height: 10,
left: i * w,
width: w - 1,
backColor: color
});
});
}
}
});
dp.init();
const app = {
loadData() {
const resources = [
{
name: "Group 1", id: "G1", expanded: true, cellsAutoUpdated: true, children: [
{ name: "Resource 1", id: "R1" },
{ name: "Resource 2", id: "R2" }
]
},
{
name: "Group 2", id: "G2", expanded: true, cellsAutoUpdated: true, children: [
{ name: "Resource 3", id: "R3" },
{ name: "Resource 4", id: "R4" },
{ name: "Resource 5", id: "R5" }
]
},
];
const events = [{
"start": "2026-04-07T00:00:00",
"end": "2026-04-11T00:00:00",
"id": "d4e5b76c-45b1-4c9f-bc3a-7d9e8b3f56cd",
"resource": "R1",
"text": "Event 1"
}, {
"start": "2026-04-09T00:00:00",
"end": "2026-04-13T00:00:00",
"id": "a2b3c7d8-e9f1-4b2a-9c0d-8e1f5a4b3c7d",
"resource": "R2",
"text": "Event 2"
}, {
"start": "2026-04-06T00:00:00",
"end": "2026-04-10T00:00:00",
"id": "b3c7d8e9-f1a2-4b2c-0d8e-1f5a4b3c7d8e",
"resource": "R3",
"text": "Event 3"
}, {
"start": "2026-04-08T00:00:00",
"end": "2026-04-14T00:00:00",
"id": "c7d8e9f1-a2b3-4c9f-0d8e-1f5a4b3c7d8e",
"resource": "R4",
"text": "Event 4"
}, {
"start": "2026-04-09T00:00:00",
"end": "2026-04-12T00:00:00",
"id": "d8e9f1a2-b3c7-4b2c-0d8e-1f5a4b3c7d8e",
"resource": "R5",
"text": "Event 5"
}];
dp.update({ resources, events });
},
init() {
this.loadData();
},
};
app.init();
DayPilot




