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

onBeforeCellRender not getting called upon update()

Asked by Tom Esh
3 years ago.

I have a onBeforeCellRender routine and when I call scheduler.update(), the onBeforeCellRender is not getting executed. I need it to be executed because I changed one of the conditions that the onBeforeCellRender usings when rendering the cell. How can I get the cells to be re-render?

I am using version 2020.4.4807.tar.gz

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

If you execute full update() the onBeforeCellRender will always be called. If you call partial update(), e.g. by specifying events only:

dp.update({events: [ ... ]});

then a cached result of onBeforeCellRender will be used.

There are three ways around this:

1. You can disable the caching using beforeCellRenderCaching (for all cells):
https://api.daypilot.org/daypilot-scheduler-beforecellrendercaching/

2. You can disabled the caching for specific resources using cellsAutoUpdated property of resources[] array items. See more in the following tutorial:
https://code.daypilot.org/93064/javascript-scheduler-column-summary

3. You can manually invalidate the cache for selected cells before calling the partial update():
https://api.daypilot.org/daypilot-cellarray-invalidate/

Comment posted by Tom Esh
3 years ago.

I am doing the following:
scheduler: DayPilot.Scheduler = new DayPilot.Scheduler("scheduler");

refresh() {
/* update the events */

this.scheduler.cells.all().invalidate(); // added
this.scheduler.beforeCellRenderCaching = false; // added
this.scheduler.update();
}
and the onBeforeCellRender doesn't get called. Am I doing something wrong?

I need to call the onBeforeCellRender because I need to disable all the cells before the current time.
Is there a better way to disable all the cells before the current time than doing it onBeforeCellRender?

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

You might want to check the logic in onBeforeCellRender. The following seems to be working fine in the console:

dp.onBeforeCellRender = function(args) { 
  if (args.cell.start < DayPilot.Date.today()) {
    args.cell.properties.disabled = true;
  }
};
dp.update();

If it still doesn't help, could you please post an example that reproduces the issue? You can generate a blank project at https://builder.daypilot.org/scheduler.

Comment posted by Tom Esh
3 years ago.

I found a fix.

I was using the following to instantiate a Scheduler instance:

     scheduler: DayPilot.Scheduler = new DayPilot.Scheduler("scheduler");

and the following in the html file:

     <daypilot-scheduler id="scheduler" [(config)]="config" [(events)]="reservations"></daypilot-scheduler>

If I change it to be:

    @ViewChild('scheduler', {static: false})
    scheduler: DayPilotSchedulerComponent;

and

   <daypilot-scheduler [(config)]="config" [(events)]="reservations" #scheduler></daypilot-scheduler>

and change all the "scheduler" references to be "scheduler.control"
Then the onBeforeCellRenderer gets called on the update() call.

Why doesn't it work when created with:

     scheduler: DayPilot.Scheduler = new DayPilot.Scheduler("scheduler");
Comment posted by Dan Letecky [DayPilot]
3 years ago.

When you add <daypilot-scheduler> to the HTML template Angular will create a placeholder div and a new DayPilot.Scheduler instance which is accessible as DayPilotSchedulerComponent.control. If you create another DayPilot.Scheduler instance it will not get you access to the first instance and its configuration.

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