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

Scheduler - Keyboard API causes an error when changing resources and events

Asked by Anonymous
2 years ago.

I'm using the keyboard API in the following events:

onTimeRangeSelecting: (args) => {
      // Update the keyboard focus during time range selection (cell click)
      if (!args.row.data.frozen) {
        this.scheduler.control.keyboard.focusCell(args.start, args.resource);
      }
    },
 onEventClick: (args) => {
      // Update the keyboard focus
      this.scheduler.control.keyboard.focusEvent(args.e);
    },
 onEventEdited: (args) => {
      // https://forums.daypilot.org/question/5600/strange-behaviour-when-navigating-using-keyboard-api-after-
      this.scheduler.control.keyboard.focusEvent(args.e);
}

All three calls causes the following error, that occures only after changing the resources and events at once:

logging.service.ts:11 TypeError: Cannot read properties of undefined (reading 'lines')
    at Object.I.Qr (daypilot-core.js:35:3672)
    at Object.I.Sr (daypilot-core.js:35:4069)
    at Object.I.Ik (daypilot-core.js:35:3909)
    at Object.b.doit (daypilot-core.js:27:6054)
    at Object.b.request (daypilot-core.js:27:5805)
    at DayPilot.Scheduler.update (daypilot-core.js:27:5635)
    at DayPilotSchedulerComponent.ngDoCheck (daypilot-angular.js:4:2400)
    at callHook (core.mjs:2536:1)
    at callHooks (core.mjs:2495:1)
    at executeCheckHooks (core.mjs:2427:1)

I'm showing in the scheduler the data of a selected person. Everytime I select a person, the resources and events properties of the scheduler are initialized with data of that person.

// Reset both arrays
this.resources = new Array();
this.events = new Array();

this.resources = this.getResources(this.person);
this.events = = this.getEvents(this.person);

this.scheduler.control.update({ resources: this.resources });
The events property is binded like this:
<daypilot-scheduler [config]="schedulerConfig" [events]="events" #scheduler>
          </daypilot-scheduler>

Is there maybe another way to do it in order to prevent this error?

Comment posted by Dan Letecky [DayPilot]
2 years ago.

Please let me check the problem.

Anyway, your update sequence causes a double update - one triggered by the this.events change and one by the explicit update() call.

I recommend the following:

1. Remove the [events] attribute (see also https://doc.daypilot.org/scheduler/angular-performance/) and load events using an update() call.

2. Merge the events and resources update.

It could look like this:

Angular template:
<daypilot-scheduler [config]="schedulerConfig" #scheduler>
          </daypilot-scheduler>
Update:
const resources = this.getResources(this.person);
const events = = this.getEvents(this.person);

this.scheduler.control.update({ resources, events });

Please let me know if the error doesn't go away after this change.

Comment posted by Anonymous
2 years ago.

Hi,
Unfortunately the problem still exists with your suggested solution, although the error occures now sometimes just once instead of infinitely. So, I still have the problem.

I had to specify the name of the properies resources and events in the update method:

this.scheduler.control.update({ resources: this.resources, events: this.events });
Comment posted by Anonymous
2 years ago.

Isn't it possible to reinitialize the whole scheduler? I mean to remove it from the DOM and add it again? Could this be a solution?

Comment posted by Dan Letecky [DayPilot]
2 years ago.

I guess it might have something to do with the previous focus state. It might help to reset the focus after the update using keyboard.resetFocus():

this.scheduler.control.update({ resources: this.resources, events: this.events });
this.scheduler.control.keyboard.resetFocus();
Comment posted by Anonymous
2 years ago.

Yes, keyboard.resetFocus() solved the problem.
Thank You!

Comment posted by Anonymous
2 years ago.

I still have the problem in certain cases. But I can' tell under which circumstances it's happening. The error "Cannot read properties of undefined (reading 'lines')" occures after calling the method update(). I tried to call keyboard.resetFocus() before update(). However it causes the same error.

Can't just reinitialize the whole scheduler to avoid this error?

Comment posted by Dan Letecky [DayPilot]
2 years ago.

Can you confirm that this error appears when the focused object (cell or event) doesn't exist after the update? E.g. when the focused event isn't in the updated data set?

It's not possible to reinitialize a static component but you can create and remove the component dynamically:
https://code.daypilot.org/28800/how-to-create-the-angular-scheduler-component-dynamically

Anyway, this issue should be fixed so if you were able to describe reproduction steps it would help a lot.

Comment posted by Anonymous
2 years ago.

After the update I always have other resources and events. But your assumption is close to the cause.

I can reproduce the error, if I focus an event or a cell in the row, that doesn't exist after the update. E. g. if I have 5 rows and I click on the last one and after the update I have six rows, then the error doesn't occure. But if the rows are less, then it happens.

Comment posted by Dan Letecky [DayPilot]
2 years ago.

Great, thanks for the update. Let me check that.

Comment posted by Anonymous
2 years ago.

Hi,
Anything new about this bug? We would like to wait for your answer before we release the next version of our software.
Thanks

Comment posted by Dan Letecky [DayPilot]
2 years ago.

Please hold on, it's in the queue... The fix will be available in the next release, which is scheduled for April 15.

Comment posted by Anonymous
2 years ago.

OK, thank you. If you're going to integrate it in the next sandbox version, then I can test in our client for you.

Answer posted by Dan Letecky [DayPilot]
2 years ago.

In the latest sandbox build (2022.2.5266), the Scheduler will try to refocus the same target (cell based on start and resource, event based on ID) after update. If the target isn't available in the updated Scheduler, it will clear the focus without any error message.

Please let me know if there is any problem.

Comment posted by Anonymous
2 years ago.

Thank you, I tested it and it seems to work

Comment posted by Dan Letecky [DayPilot]
2 years ago.

Great, thanks for the update!

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.