SOLVED

Need to hide column data when it is folder or display data when it is file on SharePoint document li

Copper Contributor

We are using "Column Formatting" option on SP document library for particular column. When it folder, then that option need to hide, if it file or document inside the folder, then option need to visible. Below json code i am trying but its is hiding option for both file and folder. Can anyone suggest us with correct code line.

 

Murali_Kurva_0-1687630008920.png

 

 

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "button",
  "customRowAction": {
    "action": "executeFlow",
    "actionParams": "{\"id\": \"\"}"
  },
  "attributes": {
    "class": "ms-fontColor-themePrimary ms-fontColor-themeDarker--hover"
  },
  "style": {
    "border": "none",
    "cursor": "pointer",
    "background-color": "#D5D5D5",
    "color": "#000",
    "padding": "4px 4px 4px 10px",
    "border-radius": "5px",
    "display": "=if([$ItemType]=='Folder', 'none', 'inherit')"
  },
  "children": [
    {
      "elmType": "span",
      "txtContent": "Request approval"
    }
  ]
}

 

 

2 Replies
best response confirmed by Murali_Kurva (Copper Contributor)
Solution

@Murali_Kurva use the following:

"visibility": "=if(((indexOf([$ContentTypeId],'0x0120')) == 0),'hidden', 'visible')"

 

 

@Murali_Kurva You have to use the [$ContentType] instead of [$ItemType].

 

Also, you will have to show/include the SharePoint default content type column in the document library view.

 

OR you can try this: 

 

"visibility": "=if([$File_x0020_Type] == '', 'hidden', 'visible')"

 

You can find similar JSON sample here: Download File Button 


Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

1 best response

Accepted Solutions
best response confirmed by Murali_Kurva (Copper Contributor)
Solution

@Murali_Kurva use the following:

"visibility": "=if(((indexOf([$ContentTypeId],'0x0120')) == 0),'hidden', 'visible')"

 

 

View solution in original post