In this article I will show (and reference) a neat piece of formatting code I found to change a year of 2020 from 2,020 to 2020 in a list view
The Problem
Simply put, if you have a number in a list in SharePoint it will add number formatting by default. A view with a Year number value of 2020 will display as 2,020
The solution
Using Colulumn formatting you can superceed the default formatting by replacing the value displayed in the field with a text value of the same thing
I found the solution on stackexchange – https://sharepoint.stackexchange.com/a/269817/48559
Select the option to format the column
Add the following into the formatting box (advanced mode)
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"attributes": {
"class": "=if(@currentField > 0,'', '')"
},
"children": [
{
"elmType": "span",
"style": {
"display": "inline-block"
}
},
{
"elmType": "span",
"txtContent": "@currentField"
}
]
}
You are a life-saver. This is literally the only correct answer on the internet for this question. Thanks for being an awesome human being.
Thanks. You saved me a lot of time. You went a step beyond the Stack Exchange post and “help my hand”.
“held my hand”…
Can’t seem to edit my previous post. Also, I tried liking your post but the WordPress API will not save my like. Crazy…
Exactly what I needed. Thanks for being so kind to share.