octabevi's avatar

Change event background color

By changing the "color" in the event properties on full calendar, it changes me only the border of the event. I want to change the event background color dynamically since I use multiple colors depending on the type.

0 likes
3 replies
MohamedTammam's avatar

What library are you using? how are you changing it? can you please share some code.

octabevi's avatar

Hi, im using Full Calendar as a librery with laravel.

In the view:

// Receive data
                    events: function(start, end, timezone, callback) {
                        console.log('nomes 1 cop :( ');
                        $.ajax({
                            url: SITEURL + "/cargarCalendarioActividadesPlanificadas",
                            type: "POST",
                            data: {
                                ubicacion_id: $('#ubicacion').val()
                            },
                            success: function(data2) {
                                console.log(data2.response);
                                callback(data2.response);
                            }
                        });
                    },

On the controller:

            $data = [];
            $colores = ["#00FF00", "blue", "green", "brown"];
            
            foreach ($eventos as $evento) {
                $data[] = [
                    'id' => $evento->ACT_ID_ACTIVITAT,
                    'title' => $evento->PLA_DESC_CURTA,
                    'start' => $evento->ACT_DATA_PLANIF,
                    'end' => $evento->ACT_DATA_PLANIF,
                    'background-color' => $colores[rand(0,3)],
                    'description' => $evento->PLA_DESCRIPCIO,
                ];
            }
    
            return response()->json(array( 'result' => true, 'response' => $data ));

Please or to participate in this conversation.