'How to set event color for individual events in FullCalendar eventSources or eventSourceSuccess

I'm using eventSources with FullCalendar 5.

Each event source returns a different type of event which is then colored differently. One source will return three different types of events, an object with three arrays wrapped, rather than having the source parse the same date range 3 times and return one array each time. Each of the three event types should be colored differently.

The eventSources entry currently looks like this:

      {
        // Reservation types
        url: '/reservations',
        method: 'POST',
        color: '#ffd5d5',
        textColor: 'black',
        eventClassNames: ['cal__reservations'],
      },

the return is:

{
  "type 1": [
    { "title": "type 1 title",
      "start": "2022-05-02",
      "end": "2022-05-02"}
    },
  "type 2": [
    { "title": "type 2 title",
      "start": "2022-05-04",
      "end": "2022-05-02"}
    },
  "type 3": [
    { "title": "type 3 title",
      "start": "2022-05-24",
      "end": "2022-05-24"}
    }
}
  

I would like to parse this return so that each type is assigned a different color, but it seems that eventSources is expecting a single array from eventSourceSuccess and that the event color is still statically defined within eventSources for each source as a whole.

Is there any way in eventSources or in eventSourceSuccess to conditionally assign a color to each event, individually?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source