Agent-readable demo data
- Title
- Monthly Event Calendar | DayPilot Pro for JavaScript Sandbox
- Tree
- DayPilot JavaScript Sandbox
- Catalog root
- Default
- Description
- Customize the component using Monthly Calendar UI Builder
and download a ready-to-run project.
Read more about the JavaScript monthly calendar.
Inline demo script 1
const dp = new DayPilot.Month("dp", {
cellMarginBottom: 20,
startDate: DayPilot.Date.today(),
onEventMoved: (args) => {
dp.message("Moved: " + args.e.text());
},
onEventResized: (args) => {
dp.message("Resized: " + args.e.text());
},
onTimeRangeSelected: async (args) => {
const modal = await DayPilot.Modal.prompt("New event name:", "Event");
dp.clearSelection();
if (!modal.result) return;
dp.events.add({
start: args.start,
end: args.end,
id: DayPilot.guid(),
text: modal.result
});
dp.message("Created");
},
onEventClicked: (args) => {
DayPilot.Modal.alert(args.e.text());
},
onHeaderClicked: (args) => {
DayPilot.Modal.alert("day: " + args.header.dayOfWeek);
},
contextMenu: new DayPilot.Menu({
items: [
{
text: "Edit",
onClick: async (args) => {
const form = [
{id: "text", name: "Event Name", type: "text"}
];
const e = args.source;
const modal = await DayPilot.Modal.form(form, e.data);
if (modal.canceled) {
return;
}
dp.events.update(modal.result);
}
},
{
text: "Delete",
onClick: (args) => {
dp.events.remove(args.source);
}
},
{text: "-"},
{
text: "Select",
onClick: (args) => {
dp.multiselect.add(args.source);
}
},
]
}),
onBeforeEventRender: args => {
args.data.areas = [
{
right: 4,
top: "calc(50% - 9px)",
width: 18,
height: 18,
style: "cursor:pointer;",
backColor: "#cccccc88",
borderRadius: "50%",
padding: 2,
fontColor: "#333333",
symbol: "../icons/daypilot.svg#threedots-h",
action: "ContextMenu",
toolTip: "Menu"
}
];
},
});
dp.init();
const app = {
loadData() {
const events = [];
let start = DayPilot.Date.today().firstDayOfMonth();
for (let i = 0; i < 15; i++) {
const add = Math.floor(Math.random() * 2);
// const add = 1;
start = start.addDays(add);
if (start.getDayOfWeek() === 6) {
start = start.addDays(2);
}
if (start.getDayOfWeek() === 0) {
start = start.addDays(1);
}
events.push({
start: start,
end: start.addDays(1),
id: DayPilot.guid(),
barColor: app.barColor(i),
text: "Event " + (i + 1)
});
}
dp.update({events});
},
barColor(i) {
const colors = ["#8FB7E3", "#A9D4A1", "#FFE38F", "#E88B8B"];
return colors[i % 4];
},
};
app.loadData();