Skip to content

Hide columns in Library based on Content Type (if folder hide, if file show) #10265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 of 9 tasks
KaveSys opened this issue May 15, 2025 · 8 comments
Open
1 of 9 tasks
Assignees
Labels
area:list-formatting-form Category: List form formatting with JSON sharepoint-developer-support sharepoint-developer-support

Comments

@KaveSys
Copy link

KaveSys commented May 15, 2025

What type of issue is this?

Question

What SharePoint development model, framework, SDK or API is this about?

💥 SharePoint Framework

Target SharePoint environment

SharePoint Online

What browser(s) / client(s) have you tested

  • 💥 Internet Explorer
  • 💥 Microsoft Edge
  • 💥 Google Chrome
  • 💥 FireFox
  • 💥 Safari
  • mobile (iOS/iPadOS)
  • mobile (Android)
  • not applicable
  • other (enter in the "Additional environment details" area below)

Additional environment details

Issue description

Hello,
There is a way to show/hide a column in Document Library based on the Content Type? I want to show a column if is a file, instead hide if is a folder.

Which is the right way to do it?

@Amey-MSFT Amey-MSFT self-assigned this May 16, 2025
@Amey-MSFT
Copy link

Hello @KaveSys,
Thank you for bringing this issue to our attention. We will look into it and get back to you shortly.

@Amey-MSFT
Copy link

Hello @KaveSys,
You can use this approach, using JSON Column Formatting with Conditional Visibility,

  1. Ensure Content Types Are Enabled:
  • Go to your Document Library settings → "Advanced settings" → Set "Allow management of content types" to Yes.
  1. Create or Use Content Types:
  • For example, default content types include Document (for files) and Folder.
  • You can also create custom content types if needed.
  1. Create Your Custom Column:
  • Add a new column (e.g., Custom Info) to the Document Library.
  1. Use Column Formatting JSON:
    You can use Column Formatting to control the visibility of the column's contents based on the Content Type.

Here's a sample JSON formatting to show a value only for files (not folders):

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "display": "=if([$ContentType] == 'Folder', 'none', 'block')"
  },
  "children": [
    {
      "elmType": "span",
      "txtContent": "[$YourColumnInternalName]"
    }
  ]
}

Replace YourColumnInternalName with the internal name of the column.

Reference Documents:-

Let me know if further help is required.
Thanks!!

@KaveSys
Copy link
Author

KaveSys commented May 16, 2025

Hello @Amey-MSFT,
thanks for the reply.

In this way should not hide the column itself from the folder list, but hide only the content of the column values:

With files:

Image

Only folders:

Image

@XueSheng-GIT
Copy link

@KaveSys: If you just want to show folders, I suggest to create a separate view with filter to show folders only and with just the columns you want to see. Wouldn't that solve your issue?

@KaveSys
Copy link
Author

KaveSys commented May 16, 2025

@XueSheng-GIT nope. Is not the scope of my request and I'm happy to explain better if it's not clear.

@XueSheng-GIT
Copy link

@KaveSys it seems at least I didn't understand the scope of your request. Would be great if you could explain better.

@KaveSys
Copy link
Author

KaveSys commented May 19, 2025

@XueSheng-GIT as you can see in images above the "Document Language" column is visible in two cases:

  1. When there are only folders in the list
  2. When there are files and folders in the list

I just want to hide the column "Document Language" only in the first case. When there are only folders in the list.
If there is at least one file (document, image, something other), then show the column "Document Language".

@Amey-MSFT
Copy link

Hello @KaveSys,
Here is a work around you can consider,
Use two views:

  • View A: For folders only (with "Document Language" hidden).

  • View B: For files and folders (with "Document Language" visible).

Then: Manually or using JSON buttons, switch between views. You can also use filters:

  • View A: Filter where File Type is empty → shows only folders

  • View B: No filters → shows all

As, according to Microsoft's documentation on Show or hide columns in a list or library, while you can manually show or hide columns in a view, there is no built-in feature to automatically hide a column based on the presence or absence of files or folders in that view.

Let me know if further help is required.
Thanks!!

@Ashlesha-MSFT Ashlesha-MSFT added sharepoint-developer-support sharepoint-developer-support area:list-formatting-form Category: List form formatting with JSON labels Jun 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:list-formatting-form Category: List form formatting with JSON sharepoint-developer-support sharepoint-developer-support
Projects
None yet
Development

No branches or pull requests

4 participants