When I set-up fullCalendar and set eventRender function callback, I want to set the color of the event depending if LeadId is null or not. But this doesn't seem to work even though the documentation says so: http://arshaw.com/fullcalendar/docs/event_data/Event_Object/#color-options
Is there any way to set the event color to change based on the data?
calendar = $('#dayview').fullCalendar({
....
timeFormat: 'HH:mm',
columnFormat: {
agendaDay: 'dddd dd/MM/yyyy'
},
eventClick: function (calEvent, jsEvent, view) {
var leadUrl = "/Leads/" + calEvent.LeadId;
window.location = leadUrl;
},
eventRender: function (event, element) {
if (event.LeadId != null) {
event.eventColor = "#B22222";
event.eventBackColor = "#B22222";
}
},
UPDATE:
This is really strange. The event has all my properties returned for the event off the server. element is just the DOM element for the event. When I drag/move the event to somewhere else in the calendar, the event turns red, and if I inspect the event object it now has color set to Red. So the question is why isn't it applying on the 1st render, but on subsequent renders (i.e. after move) the colour gets applied?
You can change the color of all events on the calendar like so: var calendar = new Calendar(calendarEl, { events: [ // my event data ], eventColor: '#378006' }); You can use any of the CSS color formats such #f00 , #ff0000 , rgb(255,0,0) , or red .
The eventRender callback function can modify element . For example, it can change its appearance via Element's style object. The function can also return a brand new element that will be used for rendering instead. For all-day background events, you must be sure to return a <td> .
Here is an example of how to specify an array of events: var calendar = new Calendar(calendarEl, { events: [ { title : 'event1', start : '2010-01-01' }, { title : 'event2', start : '2010-01-05', end : '2010-01-07' }, { title : 'event3', start : '2010-01-09T12:30:00', allDay : false // will make the time show } ] });
FullCalendar is a full-sized drag & drop event calendar. This packages is an easily consumable combination of standard plugins.
EDIT 2: Some new changes to the fc-event-skin class... it's now only fc-event, so styling shouldn't be an issue. Please check author's note here fullcalendar fc-event class...
EDIT 1: Maybe not a bug exactly.
The best approach is to set the className in the event object and add it to the elements found by an 'fc-event-skin' class. However, your added class will come later in the css and the colors will not take precedence, so you have to use !important. This also preserves the "fake" rounded corners...
Wire this method up on the calendar...
eventRender:
function (event, element, view) {
element.find('.fc-event-skin').addClass(event.className.join(' '));
}
This in your own style sheet...
.redGray
{
border-color: DarkGray !important;
background-color: LightGray !important;
color: red !important;
}
ORIGINAL ANSWER:
I think this is a minor bug in the rendering code. The element parameter is an jQuery object, so you can modify that based on your custom event data. If you set the style and text of the element, it will render with the color you set; however, it appears to me that other styles are removed from the element such as the rounded corners and the formatting of the time and text.
eventRender:
function (event, element) {
if (event.LeadId != null) {
element.css('color', 'blue');
element.css('background-color', 'yellow');
element.text(element.text);
}
I believe this is a bug, at least of sorts.
The problem is that in renderEvents
in fullcalendar.js
that the EventRender
callback is called after the function setSkinCSS
. So any changes to an element's color will not be reflected until the next time it is rendered.
I doubt the fix is easy, but I do think this qualifies as a bug. It seems to me that the RenderEvent
callback should be done very early, and certainly before the HTML is generated.
(My workaround is to try to set the element's colors well in advance of the fullcalendar calls - i.e. to not use FullCalendar's EventRender callback for setting colors)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With