I have a List in a SharePoint Online site that uses the Modern experience. I want to hide a column, but need to stay in Modern. The easy way I found was inserting a few lines of Javascript in a Script Editor webpart, but this would require switching to the Classic experience. I can't go to Classic because I have column formatting code with JSON that needs to be displayed. And I can't just remove the column from the view, because the JSON formatting references this column.
-
1If you remove column from list view...json formatting is not working??– Ganesh Sanap - MVPCommented Mar 12, 2019 at 18:26
-
Yes, the JSON formatting on another column relies on the column that I want to hide. The column "FST Sprint" has JSON formatting that references the "FSTSprintStatus" column to apply its background color. So, if FSTSprintStatus is "Red", the background color of "FST Sprint" will change to red. But, I don't want the user to see the Status column.– wahle509Commented Mar 12, 2019 at 18:53
-
I guess you can hide the status value somehow in json formatting itself??– Ganesh Sanap - MVPCommented Mar 12, 2019 at 18:55
-
I need the whole column to be hidden.– wahle509Commented Mar 12, 2019 at 19:00
-
1If you want to highlight the rows in list, you can highlight them in classic view too... By using client side rendering and JSLink.– user80093Commented Mar 12, 2019 at 19:02
2 Answers
Check the article: Customizing "modern" lists and libraries
We can't add JavaScript or CSS code in the modern list view page.
As a workaround, we can hide the column value using column formatting below, we can't hide the whole column if you need use this column value in another column formatting.
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
"elmType": "div",
"txtContent": "@currentField",
"style": {
"display": "none"
}
}
-
1I am sad we can't reference hidden columns from another column's JSON column formatting. The reason I am hiding the column in the first place, is to make a calculated column based on its value, but the column formatting I am wanting to apply to the calculated column needs to reference the original value in the hidden column (which is a date and not text (which the calculated column outputs)). Commented Jul 29, 2021 at 1:20
-
PS - there seems to be some sort of workaround here, but I have read the article and the tips in the comments multiple times and cannot understand what they are suggesting: devscopeninjas.azurewebsites.net/2019/03/18/… Commented Jul 29, 2021 at 1:45
What you need to do is create a new calculated column (or use one you already have in your view) and in its formula you will include all of the columns that you want to use in JSON formatting but don't want included in the list view itself.
If you make a new column, you should have the calculated column display the data stored in a column that you do want to display so you don't need to add an unnecessary column to your view.
Since you want to use the column [FSTSprintStatus] in your JSON formatting of column [FST Sprint], but you don't want [FSTSprintStatus] to be included in the view, you'll create a new calculated column (for this example, I'll assume the [Modified] column is in your view, so let's call the new column [FST Sprint Modified]), and you'll use a formula with a condition that always returns false, similar to this:
=IF(1==2, [FSTSprintStatus], [Modified])
You can also just use FALSE in the condition, like this:
=IF(FALSE, [FSTSprintStatus], [Modified])
Then in the view, replace [Modified] with the new [FST Sprint Modified], and now you can successfully reference [FSTSprintStatus] in the [FST Sprint] column JSON without requiring [FSTSprintStatus] to be in your view.
You can even add more columns to this formula that you want to reference in the JSON but don't want in your view. For example, you can nest the conditions like this:
=IF(FALSE, [FSTSprintStatus], IF(FALSE, [FSTSprintAmount], IF(FALSE, [FSTSprintRange], [Modified])))
Now, [FSTSprintStatus], [FSTSprintAmount], and [FSTSprintRange] can all be used in your JSON formatting and you don't need to include any of them in your view.
The trick to making this work is by ensuring that any columns you use in this way get parsed and calculated by SharePoint before the formula returns its value. For example, a formula like this won't work:
=IF(TRUE, [Modified], [FSTSprintStatus])
Since this formula returns TRUE, SharePoint returns [Modified] and immediately stops processing anything else, so [FSTSprintStatus] never gets read into the page context and cannot be referenced in the JSON. I do not know why SharePoint does it this way, I just know from previous testing of my own view formatting that it does.
Although I'm replying almost a year after you asked the question, I hope my explanation helps you out if you're still having trouble with this, or else helps someone else who's in the same boat.