SharePoint calendars: color coding, hover effects, etc.
Update [5/15/2009]: some readers have reported issues in specific cases (e.g. intraday events in calendar lists). To fix this, I have modified the post and now use “SPAN” tags instead of “DIV” tags. I’ll publish a more complete update in a couple weeks.
Update [6/8/2009]: A new version of the script is now available, more details here.
Two months ago, I introduced a method to display html in list views. The purpose of this post is to extend it to calendar views.
To learn more about the method itself, please refer to the post from September 1st. And of course, I recommend that you read the whole series about the “HTML calculated column“. You may find the following posts particularly useful:
- some simple but useful examples to get started
- a troubleshooting section
- how to apply the method to the DispForm.aspx page (as this is the page your calendar items will link to)
You can use this module alone, or combined with the ones for list views. The scripts are very similar, but I had to make some adjustments to deal with the specificities of ”a” tags.
A simple example
For my example (see above screenshot), I have chosen a variation of this post, as I wanted a printable calendar. For each task, the color depends on the % complete. Here is the formula for the calculated column:
="<SPAN style='text-align: center; background-color:"&CHOOSE(INT([%]*10)+1,"red","red","OrangeRed","OrangeRed","DarkOrange","Orange","Gold","yellow","GreenYellow","LawnGreen","Lime")&";width:100%;'>"&TEXT([%],"0%")&"</SPAN>"
Most of the examples I have already published for list views will also apply to calendar views. I have already shared a couple screenshots here.
My demo site also features a US holiday calendar with hover effects based on this method.
- if you combine the scripts for list views and calendar views, you’ll need to put the script for calendar views first.
- During my tests, I have uncovered several issues with SharePoint calendars. I am keeping an ongoing list here.
- As the method is based on calculated columns, it has some limitations (see here for more details). For example you cannot include a lookup field in a formula.
- In SharePoint calendar views, items are displayed as hyperlinks to the display form (DispForm.aspx). The hyperlink will take precedence over hyperlinks you include in your formula.
- for short events (30 min or less), SharePoint provides limited space in the day and week views. Take this into account in your design.
Special thanks to Peter and Greg who sent me a detailed report of their tests to validate the script.
The next step will be to apply the method to preview panes.