Agent-readable demo data
- Title
- SVG Export (JavaScript Event Calendar) | DayPilot Pro for JavaScript Demo
- Tree
- DayPilot JavaScript Demo
- Catalog root
- Default
- Description
- Read more about the JavaScript event calendar.
Inline demo script 1
const dp = new DayPilot.Calendar("dp", {
// view
startDate: DayPilot.Date.today(),
viewType: "Week",
allDayEventHeight: 25,
showAllDayEvents: true,
// event creating
onTimeRangeSelected: async (args) => {
const modal = await DayPilot.Modal.prompt("New event name:", "Event");
dp.clearSelection();
if (modal.canceled) {
return;
}
dp.events.add({
start: args.start,
end: args.end,
id: DayPilot.guid(),
resource: args.resource,
text: modal.result
});
dp.message("Created");
},
});
dp.init();
const app = {
elements: {
export: document.getElementById("export"),
exportButton: document.getElementById("export-button"),
downloadButton: document.getElementById("download-button"),
area: document.getElementById("area"),
},
init: function () {
this.elements.exportButton.addEventListener("click", (ev) => {
ev.preventDefault();
const area = this.elements.area.value;
const element = dp.exportAs("jpeg", {
area: area,
}).toElement();
app.elements.export.innerHTML = '';
app.elements.export.appendChild(element);
});
this.elements.downloadButton.addEventListener("click", (ev) => {
ev.preventDefault();
const area = this.elements.area.value;
dp.exportAs("svg", {
area: area,
}).download();
});
this.loadEventData();
},
loadEventData() {
const events = [
{
start: DayPilot.Date.today().addHours(12),
end: DayPilot.Date.today().addHours(15),
id: DayPilot.guid(),
text: "Special event"
},
{
start: DayPilot.Date.today(),
end: DayPilot.Date.today().addDays(3),
id: DayPilot.guid(),
allday: true,
text: "All-day event 1"
}, {
start: DayPilot.Date.today().addDays(2),
end: DayPilot.Date.today().addDays(5),
id: DayPilot.guid(),
allday: true,
text: "All-day event 2"
},
];
dp.update({events});
}
};
app.init();