Add Color to Spruce Up Your SharePoint 2007/2010 Content

You may also like...

40 Responses

  1. neil says:

    Did exactly as you said but it is not being converted to a color—only the HTML is displayed—thank you.

  2. Nikki says:


    How can I fix the code to allow more than 3 color options?


    I think my issue is with the RIGHT/LEFT thing and having 4 closing colors to thee opening place holders.



  3. Cam says:

    I’m having trouble getting this to work. Do you skip something between steps 5 and 7? My MOSS 2007 gives me the error message “The formula refers to a column that does not exist. Check the formula for spelling mistakes or change the non-existing column to an existing column” when I copy the HTML in step 6 into the Formula field.

  4. Zubair Alexander says:


    You must use an existing column in step 6. If you are not using a built-in column then create one. In my formula I referred to the column “Priority” in step 6, which already exists. If you refer to a column that doesn’t exist you will get the error that you have mentioned.

  5. Cam says:

    Thank you Zubair, this is very helpful!!!

  6. Nadeeka says:

    Thanks…. I used this… it worked properly.

  7. Jim says:


    Thank you for the complete breakdown here. I did get it to display but I have an issue. I am not able to now edit any existing record in my list without getting “an error has occurred” go back to site. Any ideas? How do I center the traffic light symbol? Is there a way to change column spacing in the Standard View?

    Thanks again!

  8. Zubair Alexander says:


    It’s hard to say why you are getting an error without knowing your configuration details, as there are so many possibilities. You might want to make sure that the code is clean…..copy it into a text editor (e.g. Notepad) before pasting it.

    To adjust the column width you’ll have to use SharePoint Designer. As far as centering the text use “text-align:center” in the code like this:

  9. Jim says:

    Hi Zubair,

    Thanks for the details on the column width. Do you have any suggestions as to why we can’t edit any record after we add the color coding code? I am not able to now edit any existing record in my list without getting “an error has occurred” go back to site.

  10. Zubair Alexander says:


    If you remove the code and are able to edit the records but when you add the code back you can’t edit the records then obviously there is something in the code that’s causing the problem. Lack of proper permissions is usually another reason why one can’t edit a list but I am assuming you have your permissions set properly. Unfortunately, “an error has occurred” error is so generic in nature that it is hard to troubleshoot without being in front of the server and knowing the configuration details for the list and for the server. As far as code, copying and pasting the code directly from Web sites is one of the more common issues. I can’t think of anything else at the moment but if something came to mind I will post it here, or send you an e-mail directly. If someone else has an answer hopefully they will post their solution here as well.

  11. Tyler says:

    I tried to download the file but the link is broken. Where can I get a copy of the file.

    Thanks – Ty

  12. Zubair Alexander says:


    I tested the link and it works fine. I just e-mailed the code to you in case the link is not working for you.

    Good luck!

  13. James says:

    Zubair – This looks awesome, but I’ve tried to get this to work but I keep on getting:

    ‘The formula contains a syntax error or is not supported’

    I first copied it into the calculated field from the web. *didn’t work
    I tried pasting into notepad and then into the calculated field. *didn’t work
    I then tried it by typing it in myself. *still didn’t work.

    Am I missing something?
    Thank you

  14. James says:

    I actually got this to work I had to include the braces [] around the column name.

    Thanks for sharing this with us.

  15. Zubair Alexander says:

    James, I am glad you found it useful.

  16. Tracy Thoman says:

    Thanks Zubair, it appears to be working for me! Question though, how do I alter the code to graphically display another column? For instance, if I have a column in a list called “Status” how do I manipulate the function code in the calculated column (and/or the code in the CEWP?) to properly display?
    Thank you,

  17. Zubair Alexander says:

    Tracy, I don’t know the answer to your question. Perhaps one of the readers might be able to answer your question.

  18. Rich says:

    Hi. I’ve implemented this and now have a nice traffic light status bullet on the a SharePoint projects site. However, when I click through to the All Items view of the list, then only the HTML is displayed, and not the coloured bullets. Is there a way to ensure the HTML gets converted in other views? Thanks.

  19. Zubair Alexander says:

    Rich, I tried using a built-in view and experienced the same issue that you have but when I created my own custom view, the colors were displayed as expected. Try creating a new Public view (doesn’t need to be the default view).

  20. George says:

    Great! It works! Here’s a question, if the PRIORITY field is null or empty, the PRIORITY STATUS field shows, #VALUE! How to I change this to show a zero length field, instead?

  21. Emily says:

    This is a great site…you helped make my SharePoint dreams come true! The instructions are easy to understand. I am a SharePoint beginner and was able to figure this out. Thanks again, Zubair!

  22. Tammy Lake says:

    I have followed yours and Christope’s instructions. My formulas are working properly in my list. The “colors” html code change when I change values, but the last piece is not working. I added a Content Edit Web part to the bottom of the page that contains my list, and put the code from your file in the Source Editor. However, I still see the html code in my list.

    Here is what is in my source editor:

    var theTDs = document.getElementsByTagName(“TD”);
    var i=0;
    var TDContent = ” “;
    while (i < theTDs.length) {
    try {
    TDContent = theTDs[i].innerText || theTDs[i].textContent;
    if ((TDContent.indexOf("<DIV") == 0) && (TDContent.indexOf("”) >= 0)) {
    theTDs[i].innerHTML = TDContent;
    // ExpGroupRenderData overwrites the default SharePoint function
    // This part is needed for collapsed groupings
    function ExpGroupRenderData(htmlToRender, groupName, isLoaded) {
    var tbody=document.getElementById(“tbod”+groupName+”_”);
    var wrapDiv=document.createElement(“DIV”);
    var theTBODYTDs = wrapDiv.getElementsByTagName(“TD”); var j=0; var TDContent = ” “;
    while (j < theTBODYTDs.length) {
    try {
    TDContent = theTBODYTDs[j].innerText || theTBODYTDs[j].textContent;
    if ((TDContent.indexOf("<DIV") == 0) && (TDContent.indexOf("”) >= 0)) {
    theTBODYTDs[j].innerHTML = TDContent;

    Here is what is in my calculate column:


    Like I said everything works and changes as expected in the list, but I don’t see bullets. Instead I see HTML.

    I’m stuck and very frustrated. Any help you can give would be very much appreciated.



  23. Priyanka says:

    Perfect !!! Thanks a lot. You are a life savior. Tons of thanks.

  24. Tom Ward says:

    We have been trying for days to get this to work, we get the html code and it does change when our status field changes.
    Yet we only get the code, we added the Web part to add the conversion but when its on the page no images appear and the html code also disappears. Haven’t tried the creating a custom view page yet that on the next try. Have verified all code and formulas even tested to see if it was a possible language pack issue.

  25. Tamar says:

    Thanks so much!

  26. Hemant says:

    How do you show these color coded columns when you need to print this list? How to edit PrintList.aspx page?

  27. Ryan Dassow says:


    This looks awesome. Exactly what my commander is trying to get me to add to our SharePoint. But I can’t seem to get this to work. At first I was getting the “The formula refers to a column that does not exist. Check the formula for spelling mistakes or change the non-existing column to an existing column.” After I added the column I was still getting a error that said, “The formula contains a syntax error or is not supported.”

    I admit I am not a whiz with HTML but is there a specific location I must put the column in the HTML code before, after, or in it?

    You could be a life saver. My commander will stop hounding me bout trying to get this done eliminating a lot of extra work.

  28. Craig says:

    Thanks for this, the only tweak I did was add “margin-top:-8px;” into the column to pull the bullets more in-line with the rest of the row.

  29. Paul says:

    Thank you very much. This is exactly what I was looking for, and very easy to get working!!!

  30. John says:

    Wow. Thank you very much. This is awesome. I have connected this to my Outlook, and added this coding to the SharePoint calendar. Is there a way of getting the color code from Outlook and adding it to the SharePoint calendar?

  31. Shobhit says:

    Thank you for a great solution.

  32. Mark says:

    Dear Zubair,
    I am attempting to set up a stoplight/traffic light display. We are running SP 2010 and when I get to the step to add a content editor web part, it does not give me a button titled “Source Editor” (step 13). When I insert the html from step 14 (which by the way, points to a different file name, not it just paints it as text and not source code.

    Can you let me know whether your example will work in 2010, or what changes I need to do to make it work? Could I accomplish this last part in SP Designer?

    I am so close, but I need your help. Very useful post!
    Thank you!


  33. Zubair Alexander says:

    I have updated the article and you can see in the screenshot exactly what you need to do in SharePoint 2010. You need to click somewhere in the Content Editor Web Part and then on the ribbon select HTML -> Edit HTML Source. You can then paste the code you copied from the convert2html.txt file. When you close the source code window, you will not see any text in the Content Editor Web Part because the code only contains a JavaScript. There is no need to use SharePoint Designer to accomplish this simple task. It should only take a few seconds to copy and paste the code.

    By the way, thanks for pointing out that the display name of the zip file didn’t match with the actual name of the zip file. I have made that correction.

  34. Joustaja says:


    I’m not able to create the calculated field (step 6). SP 2007 gives me error: The formula contains a syntax error or is not supported. I tried to copy the HTML code into notepad first and then I’ve tried to add the solid brackets around the “priority”, but did not work. Any suggestions I might try?

    When creating the column, SharePoint asks this “The data type returned from this formula is:” What box should I check? By default “single line of text” is chosen.

  35. Prasad says:

    I have applied grouping on the list view Web part but color coding is not showing up. The Div tag is being displayed in the column. Please tell me how to handle such situation, as I need to filter the Web part and color formatting should retain not div tag.

  36. Mo says:


    Please how do you guys get the HTML code showing on the list change to bullets when you added the script to the CEWP. I have tried everything, but the only thing I see is the HTML line not the bullets when added the scripts from the file.

  37. Ira says:

    Hi there,

    For some reason this code doesn’t work for me. I already have a table being imported through access, and I only want one column to be highlighted based on the information it has, i.e. the column is called Risk Rating, and if for example is the Risk rating = Low, I’d like the background to go Yellow, if RR=Critical to be red, and so on.

    I tried this code
    =” “&Status&””
    it does nothing

    than I found this online and I changed it:

    var x = document.getElementsByTagName(“TD”) // find all of the TDs
    var i=0;
    for (i=0;i<x.length;i++)

    if (x[i].className=="ms-vb2") //find the TDs styled for lists

    if (x[i].innerHTML=="Low") //find the data to use to determine the color
    x[i]'green'; // set the color

    //repeat the above for each data value

    if (x[i].innerHTML=="Moderate")
    x[i]'yellow'; // set the color

    if (x[i].innerHTML=="Critical")
    x[i]'red'; // set the color

    if (x[i].innerHTML=="High")
    x[i]'amber'; // set the color

    if (x[i].innerHTML=="Not Applicable")
    x[i]'lightgrey'; // set the color


    This one highlights all the rows but just specific colors come in actions so I don’t know which one it actually chooses.

    I’m pretty new in SharePoint/Java/HTML so any help is greatly appreciated :).


  38. Sean Docherty says:

    I tried to download the file but the link is broken. Can you please provide a new link to the file or can you re post the file for download. I have used this solution before and it worked fantastically.

    Thank you

  39. Zubair Alexander says:

    Hi Sean,

    Sorry about that. I have updated the link. If for some reason you can’t download the file please let me know so I can email it to you. Thanks for pointing out the broken link.

    Zubair Alexander

  40. Sean Docherty says:

    Hello Alex,
    Thank you for fixing the link. I was able to download the file successfully.

Leave a Reply

Your email address will not be published. Required fields are marked *

13 + seven =