Dynamically updating event color


In my scheduler project I am loading events manually into the scheduler using scheduler.parse(). This works well but now I am trying to dynamically update the color using this code:

    // Events have old color at this point
    scheduler.clearAll(); // Events are properly cleared

    scheduler.parse(events, "json"); // Events with new color gets set and rendered with new color. 

    var t = scheduler.getEvents(); // Inspecting these results show the events have the new color

    scheduler.setCurrentView(); // When this line runs, all the events go back to the old color

So something is caching the old colors somehow, and overwriting the new colors that get set when I parse the events.

If I skip the setCurrentView() line the events render properly with the new colors, but then if I change the view in any way (either a new view or just moving to the next week) the colors go back to the old colors.

What can I do to clear whatever bit of cache is holding on to the old colors?

Hi @aleks

Unfortunately, you didn’t specify the way you use to set the custom color. Did you set it into the event object? As it described here.

I tried to reproduce the issue in the snippet system and the color of the “Red event” is still red after calling scheduler.setCurrentView(). Please check: http://snippet.dhtmlx.com/5/dd0078109

If the issue still actual for you, please update the snippet code to reproduce it, then click on Share button and send me the new link. That will help me to understand what goes wrong.

Hey @Polina

I set up a snippet to show how I am updating the color, but the issue doesn’t seem to be present there, even though the code is exactly the same as my project. Snippet

In my case, the new colors show up fine after the second parse. Its only when setCurrentView is called for the second time, or if there is a view change, that the colors revert to the old ones.

Hey @Polina , nevermind. Turns out I was changing the color in the onViewChange event.


This is good news that you found a solution :slight_smile: