Calendar Colour Coding in SharePoint

It’s nice to have SharePoint calendar entries colour-coded depending on their category, location, or other metadata. In this post you will find an overview of different approaches for colour coding, applicable to SharePoint 2010 and 2007, with their advantages, difficulties and limitations.

Calendar overlay

Calendar overlay is a new feature of SharePoint 2010. Basically it is used to display several calendars in one view. As indicated by Jennifer Mason, it’s possible to overlay different views of the same calendar – this helps to display colour-coded events in one calendar.


First, you have to prepare views, one per colour. Each view has to filter events which will get the same colour.


Make one more view in which you will overlay all others. It can be one of the colour-coded views, or a view which filters all events out (so it will only show overlaid views). In the left navigation it will be shown with the title of the calendar list.

Open this view and start overlaying. Click on Calendars Overlay button on the Ribbon – Calendar.

Add each of colour-coded views by clicking New Calendar link.


Configure each overlaid view, select the colour, the calendar and the view:


Using HTML in calculated columns

Using more than ten colours is not advised by usability -  too much information is just a noise. But if you have a good reason for such solution, you can use the approach proposed by Mike Smith, Christophe@pathtosharepoint, and Mark Wilson still for SharePoint 2007. You can build HTML code in calculated columns, show these columns in calendar views, and apply a small script to process HTML.

SharePoint 2007

Step 1. Build HTML code in calculated column

In a simple example I add a choice column Colour with values red, green, and blue, and a calculated column ColourCode with HTML code.


Text formula in ColourCode column builds DIV, SPAN or just FONT tags. For example, to paint the background, use this formula:


More complicated formulas can select colours based on values of other columns, such as Category or Location.

Step 2. Show calculated columns in calendar view.

Create a new view in the calendar list based on calendar view.


In Calendar Columns section choose ColourCode as view title. (you can prepare and choose another colour-coded column for the location)


Then you get events with HTML codes in the calendar grid:


You only need to add a code which will properly show HTML.

Step 3. Add JavaScript

  • Edit the page where you want to show the view with colour coding.
  • Add the calendar list view web part and choose the view with colour coding.
  • Then add a content editor web part to the end of the page.
  • Copy the following JavaScript code to the Source Editor of the web part and save it (this script is proposed by Mike Smith).


  • Configure the web part so that it doesn’t show the title.

Here is the result:


SharePoint 2010

In SharePoint 2010 putting a content editor web part is not enough, but the evangelists of the approach propose the solution (I follow the method of Mike Smith, whose article also explains the nature of differences between the versions; Mike’s published codes are used here).

Steps 1 and 2 are the same (I just used two colours for the font and the background in the example).


The preparation of JavaScript splits to three other steps.

Step 3. Add JavaScript to master page

  • In SharePoint Designer create the master page you will use on sites displaying the calendar. You can edit the default master page v4.master, but beware of side effects! 
  • Add the following code to the very end of the master page, before the </BODY> closing tag.


Step 4. Add JavaScript to the site

  • Prepare a text file with the following script.
<script type="text/javascript" language="javascript">     function CalColor()    {      var x = document.getElementsByTagName("div")      var i=0;      for (i=0;i<x.length;i++)      {        if (x[i].className=="ms-acal-item")        {          x[i].innerHTML= x[i].innerHTML.replace(/&lt;/g,'<').replace(/&gt;/g,'>')        }      }    }     // hook into the SharePoint JS library to call our code    // whenever the calendar is updated    function CalHookIntoSPUI()    {      var originalCalendarNotify = SP.UI.ApplicationPages.CalendarNotify.$4a;      //var originalresetSelection = SP.UI.ApplicationPages.CalendarViewBase.prototype.resetSelection;       SP.UI.ApplicationPages.CalendarNotify.$4a = function()      {        originalCalendarNotify();        CalColor();      }    }     // add to the array of functions to run from the master page code    if (!window.colourCode)    {      colourCode=new Array();    }    colourCode[colourCode.length] = "CalColor";    colourCode[colourCode.length] = "CalHookIntoSPUI";   </script>
  • Save the file to a document library on the site.
  • Copy the link to the file.

Step 5. Make reference to JavaScript on the calendar page.

  • Add a content editor web part to the end of the page.
  • Edit the web part.
  • Paste the link to the script saved on step 4 to Content Link.


  • Save the web part.




Attention – limits and side effects!

1. This way we may colour-code the titles and the locations of the events. But we can do nothing about popup hints. They will show HTML codes.


It works cleaner in third party web parts. There you can make custom popup hints.

2. If there are more than three events some day, they are shown collapsed in the month view. When expanded, they show HTML codes instead of colours.


3. This way you can update the default page of the calendar listurl/calendar.aspx. In SharePoint 2007 it works without problems, but in SharePoint 2010 it breaks the Ribbon, and the calendar properties cannot be edited anymore!  

XSLT formatting

Use of content query web parts or data view web parts with XSLT formatting is natural and pretty straightforward for list views:


Making a calendar grid in XSLT would be a good puzzle for enthusiasts.

Third party solutions

SharePoint solution suppliers, such as KWizCom and Bamboo Solutions, have enhanced calendar web parts. They can roll up calendar data from various lists and represent them colour-coded. Look at KWizCom web part which shows meetings per location. It has customized popup hint with event summary for logistics people who get information about requested equipment and services.


The web part renders over views with the same names in each calendar list and shows them together in one colour. The configuration is done without any single row of code. Attention - it may get quite slow if rendering through too many views! (in the above example we have 60 lists and 360 views)

Connect to Outlook

A powerful feature of integration between SharePoint and Office is the possibility to work with SharePoint calendars in Outlook. Can we see colours in Outlook? Yes, if we use Outlook categories.

In the scenario implemented by my colleague Mel Gerats and me, we have a SharePoint calendar with consolidated data from group calendars. It is being regularly synchronised with group calendar by scheduled task. The synchronising code assigns Outlook categories according to SharePoint metadata. See a sample method which assigns categories per organisation (institute) and meeting room:  

private string TransformCategories()
    if (RawData != null)
        string categories = "";
        if (!string.IsNullOrEmpty(Organisation))
            string organisationCategory = "Institute: ";
            organisationCategory += Organisation;
            categories += organisationCategory;

        if (!string.IsNullOrEmpty(MtgRoom))
            if (!string.IsNullOrEmpty(categories))
                categories += ";";
            categories += "Room: " + MtgRoom;

        return categories;
    return "";
public string Categories
    get { return TryGetValue(RawData.Attribute("ows_Categories")); }
    set { if (RawData != null) RawData.SetAttributeValue("ows_Categories", value); }


Using prefixes, like Institute: or Room: allows to group categories by their type.

It’s not even possible to see the categories in SharePoint, nothing to say about changing them. And, to see them in Outlook, the user needs to configure all used categories on his PC, having a choice from just 16 colours in Outlook 2007, or 25 colours in Outlook 2010 (customer-specific data are hidden):


But the result is worthy of effort:


Technology Technology

Op 25/10/2010 door Orbit One

blog comments powered by Disqus