SharePoint Column Formatting – show stars that match ratings from 1 to 5

2+

Similar to what is done in the SharePoint Column Formatting – add different mood emojis that match ratings from 1 to 5 post, let’s replace rating values with corresponding number of stars. Personally, I think it even looks better.

Please note, the formatting doesn’t adjust any data. If you export your data to Excel, you will still see numeric values.

The icons are from https://developer.microsoft.com/en-us/fabric#/styles/icons

To see how it works we will create a SharePoint list, then add a “Rating” column (Number type). For example purposes, five different ratings are added with scores from 1 to 5.

To add matching number of stars to the “Rating” column, click on its header – Column settings – Format this column. Once selected, there will be a Format column window on the right side. Paste the code from down below into that windows and save to get the result.

{
	"$schema": "http://columnformatting.sharepointpnp.com/columnFormattingSchema.json",
	"elmType": "div",
	"children": [
		{
			"elmType": "span",
			"attributes": {
				"iconName": "=if(@currentField >= 5,'FavoriteStarFill','')"
			}
		},
		{
			"elmType": "span",
			"attributes": {
				"iconName": "=if(@currentField >= 4,'FavoriteStarFill','')"
			}
		},
		{
			"elmType": "span",
			"attributes": {
				"iconName": "=if(@currentField >= 3,'FavoriteStarFill','')"
			}
		},
		{
			"elmType": "span",
			"attributes": {
				"iconName": "=if(@currentField >= 2,'FavoriteStarFill','')"
			}
		},
		{
			"elmType": "span",
			"attributes": {
				"iconName": "=if(@currentField >= 1,'FavoriteStarFill','')"
			}
		}
	]
}

 

2+

Leave a Reply

Close Menu