0

I have a list in SPO with a Choice column (Video, Word, PDF). I would like to display an icon in a column called FileType.

I have tried to customize the JSON of the FileType Column but it just shows the text.

Any ideas?

enter image description here

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "box-sizing": "border-box",
    "padding": "0 2px",
    "overflow": "hidden",
    "text-overflow": "ellipsis"
  },
  "attributes": {
    "class": "sp-css-backgroundColor-BgLightGray sp-field-fontSizeSmall sp-css-color-LightGrayFont"
  },
  "txtContent": "=if([$FileType] == 'Video', 'MSNVideos', if([$FileType] == 'Word', 'WordDocument', if([$FileType] == 'PDF', 'PDF','')))"
}
3
  • This just gives blank in the FabricIcon Column ... { "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "attributes": { "iconName": "=if([$FileType] == 'PDF', 'PDF', if([$FileType] == 'Video', 'MSNVideos', if([$FileType] == 'Word', 'WordDocument')))" }, "style": { "font-size": "24px", "color": "black" } } Sep 22 at 8:58
  • Hi @PeteWhelan, did you try solution given below? Is it working for you? Nov 6 at 10:12
  • Please Upvote(^) and accept as an Answer if it helped you in any way & it will help others with similar question in future to find the correct answer easily. It also removes this question from "Unanswered questions" list. Nov 6 at 10:14

1 Answer 1

1

Try using this JSON for your column JSON formatting:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "attributes": {
    "iconName": "=if([$FileType] == 'PDF', 'PDF', if([$FileType] == 'Video', 'MSNVideos', if([$FileType] == 'Word', 'WordDocument','')))"
  },
  "style": {
    "font-size": "24px",
    "color": "black"
  }
}

Where FileType is internal name of your SharePoint list choice column. You can get the exact internal name of your SharePoint list column by following this article: How to find the Internal name of columns in SharePoint Online?

Output:

enter image description here

1
  • I have tested JSON codes provided by Ganesh Sanap and they work well. Please replace with right internal name of columns. Sep 26 at 8:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.