# Resource Management (JavaScript Scheduler) | DayPilot Lite for JavaScript Demo

> Use the pencil and trash icons in each row header to rename or remove a resource. Removing a group also removes its nested resources and bookings. You can create, move and resize bookings.

## Links

- Canonical HTML: /demo/lite/scheduler/resourcemanagement.html
- Source HTML folder: /demo/lite/scheduler/
- Catalog root: /demo/lite/
- Catalog: /demo/lite/llms.txt

## Source

### Inline demo script 1

```javascript
const dp = new DayPilot.Scheduler("dp", {
            startDate: DayPilot.Date.today().firstDayOfMonth(),
            days: DayPilot.Date.today().daysInMonth(),
            scale: "Day",
            timeHeaders: [{groupBy: "Month"}, {groupBy: "Day", format: "d"}],
            cellWidth: 56,
            rowHeaderWidth: 300,
            heightSpec: "Max",
            height: 430,
            rowMarginTop: 4,
            rowMarginBottom: 4,
            treeEnabled: true,
            treePreventParentUsage: true,
            onBeforeRowHeaderRender: args => {
                args.row.areas = [
                    {
                        right: 38, top: "calc(50% - 12px)", width: 26, height: 24,
                        visibility: "Visible", action: "None", cursor: "pointer",
                        cssClass: "resource-action resource-rename", padding: 4,
                        symbol: "../icons/daypilot.svg#edit",
                        toolTip: "Rename " + args.row.name,
                        onClick: args => app.renameResource(args.source)
                    },
                    {
                        right: 6, top: "calc(50% - 12px)", width: 26, height: 24,
                        visibility: "Visible", action: "None", cursor: "pointer",
                        cssClass: "resource-action resource-remove", padding: 4,
                        symbol: "../icons/daypilot.svg#trash",
                        toolTip: "Remove " + args.row.name,
                        onClick: args => app.removeResource(args.source)
                    }
                ];
            },
            onTimeRangeSelected: async args => {
                const modal = await DayPilot.Modal.prompt("Booking name:", "New booking");
                dp.clearSelection();
                if (modal.canceled) {
                    return;
                }
                dp.events.add({id: DayPilot.guid(), resource: args.resource, text: modal.result,
                    start: args.start, end: args.end});
            }
        });

        const app = {
            elements: {
                reset: document.getElementById("reset-resources"),
                status: document.getElementById("resource-status")
            },
            init() {
                dp.init();
                this.elements.reset.addEventListener("click", () => this.reset());
                this.reset();
            },
            reset() {
                const resources = [
                    {id: "studio", name: "Product studio", expanded: true, children: [
                        {id: "design", name: "Design", expanded: true, children: [
                            {id: "A", name: "Alex Morgan"},
                            {id: "B", name: "Casey Brooks"}
                        ]},
                        {id: "development", name: "Development", expanded: true, children: [
                            {id: "C", name: "Jordan Lee"},
                            {id: "D", name: "Taylor Reed"}
                        ]}
                    ]},
                    {id: "operations", name: "Operations", expanded: true, children: [
                        {id: "E", name: "Robin Ellis"},
                        {id: "F", name: "Sam Parker"}
                    ]}
                ];
                const titles = ["Interface design", "User research", "API development", "Component library", "Test planning", "Device testing"];
                const events = titles.map((text, i) => ({id: i + 1, resource: String.fromCharCode(65 + i),
                    start: dp.startDate.addDays(i % 3 + 1), end: dp.startDate.addDays(i % 3 + 5), text}));
                dp.update({resources, events});
                this.elements.status.textContent = "Sample resources and bookings restored.";
            },
            async renameResource(resource) {
                const modal = await DayPilot.Modal.prompt("Resource name:", resource.name);
                if (modal.canceled) {
                    return;
                }
                const name = modal.result.trim();
                if (!name) {
                    this.elements.status.textContent = "Enter a resource name.";
                    return;
                }
                const row = dp.rows.find(resource.id);
                if (!row) {
                    return;
                }
                row.data.name = name;
                dp.rows.update(row);
                this.elements.status.textContent = "Renamed to “" + name + "”. Resource IDs and bookings are preserved.";
            },
            async removeResource(resource) {
                const ids = new Set();
                const collect = row => {
                    ids.add(row.id);
                    row.children().forEach(collect);
                };
                collect(resource);
                const events = dp.events.list.filter(event => ids.has(event.resource));
                const message = "Remove “" + DayPilot.Util.escapeHtml(resource.name) + "”"
                    + (ids.size > 1 ? " and its " + (ids.size - 1) + " nested resources" : "")
                    + "? This also removes " + events.length + " associated booking" + (events.length === 1 ? "." : "s.");
                const modal = await DayPilot.Modal.confirm(message);
                if (modal.canceled) {
                    return;
                }
                const row = dp.rows.find(resource.id);
                if (!row) {
                    return;
                }
                // Booking removal is an application decision; rows.remove() removes resources.
                const remaining = dp.events.list.filter(event => !ids.has(event.resource));
                dp.rows.remove(row);
                dp.update({events: remaining});
                this.elements.status.textContent = "Removed “" + resource.name + "” and its associated bookings.";
            }
        };
        app.init();
```

