search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Unable to dp.init() in Lightning Web Component

Asked by Thaddeus
11 months ago.

Using the javascript scheduler capability the following error message is returned when attempting to init() the scheduler instance.

DayPilot.Scheduler: The placeholder element not found: 'dp'.

How is the element placeholder passed to the div class?

HTML:

    <template>
        <div class="dp" lwc:dom="manual" style='width: 100%;' id="dp"></div>
    </template>

JS

        const dp = new window.DayPilot.Scheduler("dp", {
            timeHeaders: [{"groupBy":"Year"},{"groupBy":"Month"},{"groupBy":"Day","format":"d"}],
            scale: "Day",
            days: "365",
            startDate: "2023-01-01",
            showNonBusiness: false,
            eventMovingStartEndEnabled: true,
            timeRangeSelectedHandling: "Enabled",
            onTimeRangeSelected: async (args) => {
              const dp = args.control;
              const modal = await DayPilot.Modal.prompt("Create a new event:", "Event 1");
              dp.clearSelection();
              if (modal.canceled) { return; }
              dp.events.add({
                start: args.start,
                end: args.end,
                id: DayPilot.guid(),
                resource: args.resource,
                text: modal.result
              });
            treeEnabled: true,
          });

        dp.resources = [
        {
    ];
    dp.events.list = [  {
    }];
        dp.init();

Answer posted by Dan Letecky [DayPilot]
11 months ago.

LWC uses virtual DOM so you will need to adjust the code a bit.

1. Make sure that the init code is in renderedCallback(). This ensures that the placeholder will be available.
2. The DayPilot.Scheduler constructor accepts either the placeholder id (string) or the DOM element (https://api.daypilot.org/daypilot-scheduler-constructor/). In this case, you will need to get a DOM element reference using this.template.querySelector() - see https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.security_locker_dom

const el = this.template.querySelector('#dp');
const dp = new window.DayPilot.Scheduler(el, { ... });
This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.