Agent-readable demo data

Title
Drag and Drop Event Moving over Non-Business Hours (JavaScript Scheduler) | DayPilot Pro for JavaScript Demo
Tree
DayPilot JavaScript Demo
Catalog root
Default
Description
Non-business and hidden cells are skipped during drag-and-drop event moving.

Inline demo script 1

const dp = new DayPilot.Scheduler("dp", {
            startDate: "2027-01-01",
            days: 365,
            scale: "Day",
            timeHeaders: [
                { groupBy: "Month", format: "MMMM yyyy" },
                { groupBy: "Cell", format: "d" }
            ],
            treeEnabled: true,
            resources: [
                {
                    name: "Locations", id: "G1", expanded: true, children: [
                        { name: "Room 1", id: "A" },
                        { name: "Room 2", id: "B" },
                        { name: "Room 3", id: "C" },
                        { name: "Room 4", id: "D" }
                    ]
                },
                {
                    name: "People", id: "G2", expanded: true, children: [
                        { name: "Person 1", id: "E" },
                        { name: "Person 2", id: "F" },
                        { name: "Person 3", id: "G" },
                        { name: "Person 4", id: "H" }
                    ]
                },
                {
                    name: "Tools", id: "G3", expanded: true, children: [
                        { name: "Tool 1", id: "I" },
                        { name: "Tool 2", id: "J" },
                        { name: "Tool 3", id: "K" },
                        { name: "Tool 4", id: "L" }
                    ]
                },
            ],
            onBeforeEventRender: (args) => {
                args.data.bubbleHtml = `<div><b>${args.e.text}</b></div>`
                    + `<div>Start: ${new DayPilot.Date(args.e.start).toString()}</div>`
                    + `<div>End: ${new DayPilot.Date(args.e.end).toString()}</div>`;
                if (args.data.x) {
                    args.data.html = args.data.x + "/" + args.data.y;
                }
                if (args.data.text.includes("Event 3")) {
                    args.data.moveSkipNonBusinessDisabled = true;
                    args.data.text += " (non-business skipping disabled)";
                }
            },
            onBeforeCellRender: (args) => {
                if (dp.clientState.customPattern) {
                    const day = args.cell.start.getDayOfWeek();
                    args.cell.business = ![0, 3, 5].includes(day);
                }
            },
            onTimeRangeSelected: async (args) => {
                const modal = await DayPilot.Modal.prompt("New event name:", "Event");
                dp.clearSelection();
                if (modal.canceled) {
                    return;
                }
                const name = modal.result;
                dp.events.add({
                    start: args.start,
                    end: args.end,
                    id: DayPilot.guid(),
                    resource: args.resource,
                    text: name
                });
                dp.message("Created");
            },
            eventMoveSkipNonBusiness: true,
            showNonBusiness: true,
            height: 350
        });
        dp.init();
        const app = {
            elements: {
                weekends: document.querySelectorAll("input[name='nb']"),
                pattern: document.querySelector("#pattern")
            },
            init() {
                dp.scrollTo("2027-08-25");
                this.addEventHandlers();
                this.loadEventData();
            },
            addEventHandlers() {
                this.elements.weekends.forEach(input => {
                    input.addEventListener("change", ev => {
                        this.showWeekends(ev.target.value === "true");
                    });
                });
                this.elements.pattern.addEventListener("change", ev => {
                    this.applyPattern(ev.target.checked);
                });
            },
            showWeekends(visible) {
                const start = dp.getViewPort().start;
                dp.update({showNonBusiness: visible});
                dp.scrollTo(start);
            },
            applyPattern(enabled) {
                dp.clientState.customPattern = enabled;
                dp.update();
            },
            loadEventData() {
                const events = [];
                for (let i = 0; i < 12; 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 e = {
                        start: new DayPilot.Date("2027-08-25T00:00:00").addDays(start),
                        end: new DayPilot.Date("2027-08-25T12:00:00").addDays(start).addDays(durationDays).addHours(duration),
                        id: DayPilot.guid(),
                        resource: String.fromCharCode(65 + i),
                        text: "Event " + (i + 1)
                    };
                    events.push(e);
                }
                dp.update({ events });
            }
        };
        app.init();