Recently, I was discussing a clever trick with a colleague, for showing HTML in a SharePoint column.
Source column : Priority
Firstly, we need to add a column that we’ll use at the ‘checker’ column – this might be something like a STATUS column, or % COMPLETE, or PRIORITY.
- Create Column : Priority
- Type : Number
Add some List Data
Just add a few items to the list – and pick some priorities.
You can do whatever VIEWS, or SORTING or GROUPING – whatever…!
Find some images
Save these images locally – and upload to your SharePoint site – eg. SiteAssets, or Style Library. I’ve loaded mine into an “IMG” folder.
Eg. /Style Library/IMG/red.png
We can now do the magic + fun bit.
- Create a calculated column : Indicator
- Type : Calculated
- Formula :
=”<DIV><img src='” & IF(Priority=1, “/Style Library/IMG/red.png”, IF(Priority=2,”/Style Library/IMG/yellow.png”, IF(Priority=3,”/Style Library/IMG/green.png”, IF(Priority=4,”/Style Library/IMG/blue.png”)))) & “‘></DIV>”
This is essentially doing the following :
- If Status = 1, put an IMG tag for RED
- If Status = 2, put an IMG tag for YELLOW
NB. The way that the formula works is like EXCEL :
- IF (condition, TRUE, FALSE)
This method (above) is nesting these :
- IF (condition1, IMAGE, IF (condition2, IMAGE, IF (condition3, IMAGE, IMAGE ) ) )
Click back to your list to view your column :
What the !!?! It’s just showing HTML !!
The UberMagic Tip
But no – the amazingly simple tip is this :
- Change the return type to be a NUMBER.
Yep. If defies logic – and doesn’t make sense – might even be a BUG !
But – it works.
Take a bow
If you’ve done the steps correctly, it should look like this :
Too easy – right !!?!
** You might need to include the ‘site collection’ prefix within the formula – pro tip !
=”<DIV><img src='” & IF(Priority=1, “/sites/SC1/Style Library/IMG/red.png”, IF(Priority=2,”/sites/SC1/Style Library/IMG/yellow.png”, IF(Priority=3,”/sites/SC1/Style Library/IMG/green.png”, IF(Priority=4,”/sites/SC1/Style Library/IMG/blue.png”)))) & “‘></DIV>”
Check this blog for some other renditions – very cool !
Let me know if you like this tip – my buddy DanCol was #MindBlown over this one !