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

Scheduler ContextMenu with async loaded data

Asked by Tim K.
3 years ago.

Hello,
we are using the Scheduler ContextMenu and want to manipulate the ContextMenu-Items dynamically. Therefore we use the "onShow"-Event of the DayPilot.Menu class.

By clicking on the event, we request data from server async and react on the result by disable/enable the ctxMenu item.

Our problem is, that the ContextMenu doesn`t consider the disable-option, however we`ve seen that the option is set correctly. We assume that the ContextMenu is rendered before our onShow-function is completed.

For other events as Scheduler.onScroll there are the options "args.async" and "args.loaded()". This looks like the functionality, that we need to handle our purpose.

Can you agree with our assumption? Is it possible to implement this options for the onShow-Event?

KR
Tim

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

Yes, it works as you describe.

At this moment, the args.async option is not supported in the onShow() method but you can switch to manual event click/right click handling and open the context menu when you have the data available.

Like this:

dp.onEventRightClick = async args => {
  args.preventDefault(); // disable the default action
  const data = await loadData(...); // your data loading method

  const menu = new DayPilot.Menu({ ... }); // build the menu dynamically or adjust dp.contextMenu
  menu.show(e);
};
Answer posted by Tim K.
3 years ago.

This works fine for me. Thank you!

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