Agent-readable demo data

Title
Event Multi-Selecting (JavaScript Scheduler) | DayPilot Pro for JavaScript Demo
Tree
DayPilot JavaScript Demo
Catalog root
Default
Description
Select multiple events using Shift + mouse drag. Use Ctrl + click to add/remove events from selection. Read more about selecting multiple events.

Inline demo script 1

const dp = new DayPilot.Scheduler("dp", {
            startDate: "2026-01-01",
            days: 365,
            scale: "Day",
            timeHeaders: [
                {groupBy: "Month", format: "MMMM yyyy"},
                {groupBy: "Cell", format: "d"}
            ],
            treeEnabled: true,
            resources: [
                {name: "Room A", id: "A"},
                {name: "Room B", id: "B"},
                {name: "Room C", id: "C"},
                {name: "Room D", id: "D"},
                {name: "Room E", id: "E"},
                {name: "Room F", id: "F"},
                {name: "Room G", id: "G"},
                {name: "Room H", id: "H"},
                {name: "Room I", id: "I"},
                {name: "Room J", id: "J"},
                {name: "Room K", id: "K"}
            ],
            onTimeRangeSelected: async args => {
                const modal = await DayPilot.Modal.prompt("New event name:", "Event");
                if (modal.canceled) {
                    return;
                }
                dp.events.add({
                    start: args.start,
                    end: args.end,
                    id: DayPilot.guid(),
                    resource: args.resource,
                    text: name
                });
                dp.message("Created");
            },
            rectangleSelectMode: "Free",
            rectangleSelectHandling: "EventSelect",
            eventClickHandling: "Select",
            onRectangleSelecting: args => {
                const msg = args.events.map(item => item.text()).join(" ");
                app.elements.msg?.replaceChildren(msg);
            },
            onRectangleSelect: args => {
                // console.log(args.start + " " + args.end);
                // console.log(args.resources);
                console.log("args.events: " + args.events.map(item => item.text()));
            },
            onRectangleSelected: args => {
                app.elements.msg?.replaceChildren("(selection complete)");
            },
            onGridMouseDown: args => {
                if (app.switchShift) {
                    if (args.shift) {
                        args.action = "TimeRangeSelect";
                    } else {
                        args.action = "RectangleSelect";
                    }
                }
            },
            height: 280
        });
        dp.init();
        dp.scrollTo("2026-03-25");

        const app = {
            elements: {
                mode: document.querySelector("#mode"),
                shift: document.querySelector("#shift"),
                msg: document.querySelector(".msg"),
            },
            switchShift: false,
            init() {
                this.addEventHandlers();
                this.loadEventData();
            },
            addEventHandlers() {
                app.elements.mode.addEventListener("change", function() {
                    dp.rectangleSelectMode = app.elements.mode.value;
                });

                app.elements.shift.addEventListener("change", function() {
                    app.switchShift = app.elements.shift.checked;
                    console.log("switchShift: " + app.switchShift);
                });
            },
            loadEventData() {
                const events = [];

                for (let i = 0; i < 15; i++) {
                    const duration = Math.floor(Math.random() * 6) + 1; // 1 to 6
                    const durationDays = Math.floor(Math.random() * 6); // 0 to 5
                    const start = Math.floor(Math.random() * 6) + 2; // 2 to 7

                    const event = {
                        start: new DayPilot.Date("2026-03-25T00:00:00").addDays(start),
                        end: new DayPilot.Date("2026-03-25T12:00:00").addDays(start).addDays(durationDays).addHours(duration),
                        id: DayPilot.guid(),
                        resource: String.fromCharCode(65 + i),
                        text: "Event " + (i + 1),
                    };

                    events.push(event);
                }

                dp.update({events});
            }
        };
        app.init();