Forum Discussion
Eliot_Cole
Jun 23, 2025Iron Contributor
List Column Formatting - Set WHOLE Attributes Object If Column Has Content
Hi, I would essentially like to know how to achieve one of two outcomes in my view formatting dependent on the column in question having a value. The following are the two eventualities I would like...
grant_jenkins
Jun 26, 2025Iron Contributor
Eliot_Cole I would add two elements to your JSON but only show one of them depending on if the field has a value. This way you would show the "a" element if there was a value, and a "span" if there wasn't a value.
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"children": [
{
"elmType": "span",
"style": {
"display": "=if(@currentField=='', '=', 'none')"
},
"txtContent": "No Url"
},
{
"elmType": "a",
"style": {
"display": "=if(@currentField=='', 'none', '')"
},
"txtContent": "@currentField",
"attributes": {
"target": "_blank",
"href": "@currentField"
}
}
]
}
- Eliot_ColeAug 06, 2025Iron Contributor
I gotta ask, grant_jenkins, how does the span thing work?
Because, as far as I can grep, that is creating this CSS:
span { display: =; }Am I going crazy? 😅🤪