Forum Discussion
CubanGuy
Apr 19, 2022Copper Contributor
SharePoint JSON formatting document library columns
I'm using a JSON Formatting in one of the columns of a document library, and so far works just fine. I have only one issue. The documents inside the library are organized in folders, and those docume...
CubanGuy
Apr 19, 2022Copper Contributor
I think I figured it out. It won't hide the columns from view, but at least won't show the NaN. Just in case someone is in a similar situation. I used the Content Type column to do the trick:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"attributes": {
"class": "=if(@currentField > 0,'', '')"
},
"children": [
{
"elmType": "span",
"txtContent": "=if([$ContentType] != 'Folder', if(Number([$YearPublished]) != 0, floor(Number(getYear(@now)) - Number([$YearPublished])), 'Year Published not provided'), '')"
}
]
}