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

beforeCellRenderCaching in 'normal' calendar

Asked by Mark
8 days ago.

Hello,

we are using the DayPilot pro (latest) version of the JavaScript Calendar. We are using the onBeforeRenderCell event to colorize the calendar cells, to set disable and business cell properties. When we change some data in the backend and reload the calendar, the colors are not changed, even the beforeRenderCell is called, but the colors are not changed. The colors seems to be cached.

I looked up the forum and I found a feature called “beforeCellRenderCaching”, which is implemented in the calendar scheduler component. Is there something I can do in the normal calendar to disable the cell caching? Maybe a workaround? Or will this feature be implemented for the normal calendar in future?

Best regards!

Mark

Comment posted by Dan Letecky [DayPilot]
8 days ago.

In the Calendar component, the result of onBeforeCellRender is not cached.

However, the cells will not be updated if you only update events like this:

const eventData = [ ... ];
calendar.update({events: eventData});

Calling update() with events as the single property of the options param will trigger an optimized update.

Anyway, in that case onBeforeCellRender shouldn’t be invoked.

How do you update the Calendar?

Comment posted by Mark
7 days ago.

Thanks for the fast answer, but maybe my request was a bit vague.

The event rendering and event color is fine, we have a problem with the calendar cell background color, which is not refreshed, after the color was changed.

In our backend data object, we have e.g the business days of an area.

Simple example:

  • 26.11.2024: non business day -> helper function returns false and calendar cell background is rendered #FF0000

  • When I now change the 26.11.2024 to a business day and reload the calendar

  • The onBeforeCellRender function is triggered, the helper function rerturns true, so the backColor property is changed to #00FF00

  • Visually the calendar backColor is still on color #FF0000

  • When I restart the complete application, the backColor is rendered correctly. Now I can do the same the other way round.

    It feels like the backColor is cached, and not refreshed, even it was set to a new color. That’s why I mentioned the beforeCellRenderCaching property from scheduler component.

Calendar.onBeforeCellRender = args => {
   if (this.IsBusinessCell(args.cell.start)) {
      args.cell.properties.backColor = "#00FF00";
      args.cell.properties.business = true;
      args.cell.properties.disabled = false;
   } else {
      args.cell.properties.backColor = "#FF0000";
      args.cell.properties.business = false;
      args.cell.properties.disabled = true;
   }
}
Comment posted by Dan Letecky [DayPilot]
7 days ago.

Thanks for the update, Mark.

It might be related to the way you refresh the Calendar:

> When I now change the 26.11.2024 to a business day and reload the calendar

Could you please post this piece of code?

Answer posted by Mark
7 days ago.

Hello Dan,

while I was preparing some code for this issue, I found the mistake myself… my backend data was fetched via rest call correctly, but the data was not assigned to the object, which I use in my logic. Now it works as expected! Really stupid of myself!

Sorry for wasting your time!

Best regards,

Mark

Comment posted by Dan Letecky [DayPilot]
7 days ago.

Hi Mark,

I’m glad that it’s working - thanks for the update!

New Reply
This reply is
Attachments:
or drop files here
Your name (optional):