Hide JSON built hyperlink in SharePoint list if there’s no underlying link
Posted On December 9, 2020
“Is there any way to modify the JSON on SharePoint column to hide the “Open” link if there’s no underlying hyperlink?”
“I have a list with links to documents, but there isn’t always a link because there isn’t always a document yet. I don’t want people getting frustrated with dead links.”
When using JSON to format a hyperlink, e.g. to replace Calculated column with hyperlink, you might have some items where the link is empty. In that case you’ll end up with the description text, but no link on the background. Text that look like a link, but leads nowhere. How can you hide this fields and keep only the exiting ones?
Add “style” to the JSON
You can extend the JSON column formatting by adding “style” attribute with an ‘if condition’. If the column with link is empty, apply style “display: none” to hide the column. Otherwise use “display: inherit” to show the link.
The piece of code above will display text “Open” only if the current field is not empty. And you can use not only the current field, but also any other column referenced by [$columName] in the condition.