Color-Coding a SharePoint List Without Javascript

christineAdministrator Guides, SharePoint, Templates & DownloadsLeave a Comment

color-coded-list-sharepoint

I’ve tried following quite a few tutorials for color-coding that use Javascript (such as this one), but couldn’t get a single one to work in SharePoint Online. As a workaround, I made my own color-coding method using a concatenate formula in a calculated column.

How it Works

Calculated columns in SharePoint that have the type “number” can render HTML via a concatenate formula. I used a choice column with red, yellow, and green in a dropdown, but any HTML colors will work for the color selection. Then I made a formula that creates a square div and uses that same color as the background color in the CSS like this:

=CONCATENATE("<div style=",CHAR(34),"height:20px;width:20px;border-radius:3px;background-color:",[Color],CHAR(34),">&nbsp;</div>")

The CHAR(34) bits are the mechanism for inserting quotations in a concatenate formula (they are used in the CSS), the [Color] is the color value from the choice column. As long as you provide choices that are valid HTML color names, this will color your box according to whichever option is selected!

Instructions

To create this from scratch, create a custom list or a task list, then add a “choice” column with color names from the color list linked above. Making it required is a good idea. Then add a calculated column number type column, paste in the formula above, and replace the [Color] value with your choice column name.

sharepoint calculated column concatenate formula for html

Make sure your new calculated column is displayed in your list view (you may want to hide the text color value and just leave it in the form, too). Remember that you can save the list as a template for use in other sites.

Here’s an example with more colors from the web color list!

colors in sharepoint list

Caveats

SharePoint likes to make number calculated columns align right… the alignment is done via align tags in the HTML, and I can’t figure out how to get it to align left or center instead. Making your column name short will make the alignment less noticeable (note column name above follows this rule – “Tag”).

Leave a Reply

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