3

I've been able to easily hide any toolbar button by using "Format current view" and adding the JSON.

{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/row-formatting.schema.json",
"commandBarProps": {
"commands": [
    {
      "key": "download",
      "hide": true
    },
   {
      "key": "copyLink",
      "hide": true
   }
  ]
 }
}

But how do I edit the Item context action menu? I would also like to know if it is possible to hide the whole menu.

Context action menu

Also, I currently don't have SharePoint Designer, but I could get it if needed. I've seen some info around for SPFx, but I have never done anything in SPFx. A need a simple solution if there is one, lol. Also, on my wish list is getting rid of the Share button.

Thanks in advance!

1 Answer 1

4

First of all, you cannot hide individual context menu options using JSON formatting. You can only customize/hide options from command bar at the top.

You can hide "Share" option from command bar using `` as key like:

{
    "key": "share",
    "hide": true
}

Documentation: Command bar customization syntax reference


You can hide complete context menu from list view using two methods:

Method 1 - SharePoint OOTB:

In SharePoint list, Title column has three different variants:

  • Title
  • Title (linked to item)
  • Title (linked to item with edit menu)

So, you can use plain "Title" column in your list view to hide context menu.

Method 2 - JSON formatting:

You can add simple JSON formatting on Title column like below to hide context menu:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "@currentField"
}

While using JSON formatting, you will loose all OOTB functionality formatting for Title column including default click which open display/view form of list, you can get it back using JSON formatting on Title column like:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "@currentField",
  "customRowAction": {
    "action": "defaultClick"
  },
  "attributes": {
    "class": "sp-field-underline"
  }
}

Update from comments:

As you are using document library, you have to apply column formatting on Name column instead of Title column: :

Format option:

enter image description here

Then go to "Advanced mode":

enter image description here

Copy-paste above JSON and click "Save":

enter image description here

You can apply additional styling as per your requirements. Check below documentation for more information:

  1. Use Column formatting in SharePoint
  2. JSON formatting-syntax-reference
10
  • I added the code below to my "No Context Menu" view > Format current view. "Share" still displays in the top toolbar, even for my Read only/Visitor role. { "$schema": "developer.microsoft.com/json-schemas/sp/v2/…", "commandBarProps": { "commands": [ { "key": "share", "hide": true } ] } } Nov 1, 2022 at 21:29
  • Sharing Permissions set to: Only site owners can share files, folders, and the site. Did I do something wrong? Nov 1, 2022 at 21:34
  • Method 1: Please note, I am a newbie and I need more information to try your answer. Regarding Method 1. I added the "Title" column to my view, the Context Menu no longer displays. Yea! Thanks. Is there JSON to get it to populate with the File Name? Nov 1, 2022 at 22:04
  • 1
    Thank you so much for the additional info! Adding the JSON to the column works great!!!! Nov 2, 2022 at 18:56
  • 1
    Thank you for the link to Syntax. This works to fix the font: { "$schema": "developer.microsoft.com/json-schemas/sp/v2/…", "elmType": "div", "style": { "font-size": "14px" }, "txtContent": "@currentField", "customRowAction": { "action": "defaultClick" } } Nov 5, 2022 at 17:42

Your Answer

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

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