For SharePoint 2010 – go to the end of this article.
This article was written by a friend and colleague of mine, Richard Granger. In it, he explains an approach to making calendar events color coded inside SharePoint.
I have run into situations where I would like to differentiate calendar events by color. For instance if I have a leave calendar I want all vacation to be colored red, sick leave colored black, travel colored green, and so on. After doing some research I found that this can be accomplished with sharepoint out of the box using some calculated columns and a content editor web part.
Step 1 – Setting up your calendar
Start by navigating to the calendar that you are working with and access the calendar settings. Add a column to the list that will be used to differentiate the calendar events. I recommend using a choice column. For example if you are working with a leave calendar you could add a column called Leave Type with choices of: vacation, sick, training, telework, travel, etc…
Step 2 – Create calculate columns
While still in the calendar settings we will want to add two more columns. The first column will be called ‘Color’ and will be calculated column. The following formula will set the value of the Color column based off of the value selected in the Leave Type column. Obviously you will want to change all of the [Leave Type] text to the field you created in step 1. Also you can play with the colors that you desire. For instance I use “Green” but “DarkGreen” is also an option. Feel free to try if it does not recognize the color you will know because it will not render properly. Also in my example I have eight choices and if you do not require that many options its not a problem. But if you have more than eight options and try to nest another IF statement sharepoint will not accept it. If you do need to have more than eight options follow the logic in the second formula.
=IF([Leave Type]=”Leave Without Pay”,”Olive”,IF([Leave Type]=”Annual”,”Red”,IF([Leave Type]=”Sick”,”Black”,IF([Leave Type]=”Travel”,”Green”,IF([Leave Type]=”Training”,”DarkBlue”,IF([Leave Type]=”Telework”,”DarkCyan”,IF([Leave Type]=”Compensatory Time Off”,”DarkRed”,IF([Leave Type]=”Other Paid Absence”,”Purple”,””))))))))
The second column will be called ‘Display’ and will also be a calculated column. Copy and paste the following text into the formula.
=”<span style=’position:relative;display:inline-block;width:100%;’><span style=’width:100%;display:inline-block;text-align:center;border:1px solid “&Color&”;position:absolute;color:”&Color&”;’> “&Title&”</span><span style=’display:inline-block;width: 100%;background-color:”&Color&”;text-align:center;border:1px solid;z-index:-1;filter:alpha(opacity=20);opacity:0.2;’>”&Title&”</span></span>”
The ‘Display’ column is colorizing the Title column. You can use the ‘Display’ column to colorize any other column simply by replacing Title with the column name of your choice.
Step 3 – Set up calendar views
Staying on this page click on the Calendar view at the bottom of this page. On the view page change the ‘Month View Type’, ‘Week View Type’, and ‘Day View Type’ from ‘Title’ to ‘Display’. Now go back to the calendar view and you will see that you get a nasty looking display for the calendar items which we will fix in step 4
Step 4 – Fix the item display
- Go to your calendar view and switch the web page to edit mode.
- Click add web part and select the content editor web part.
- Drag and drop the calendar view above the content editor web part (this is important)
- in the Content Editor Web Part, click on “open the tool pane”
- Click on the Source button and paste the following text into the window.
Once you click OK on the tool pane and you should now see that your calendar is displaying color coded events.
HTML Color Chart. Click on a color and the name will be shown. You can use that color name in the equation above.
RGB Color Chart. You cannot use these colors by name in the formula above but can reference their RGB value.
A big thanks to Richard for taking the time to share this with everyone!
UPDATE – SHAREPOINT 2010
If you want to do color coding in SharePoint 2010, use the Calendar Overlay feature. I found a great blog describing how to do it: http://bitwizards.com/Blogs/Mylene-Biddle/May-2012/Creating-Color-Coded-Calendar-Events-in-SharePoint
Took me about 5 minutes to do and, since it is out of the box capability, it is fully supported. Easy!