locked
How to hide "Delete Item" from ECB menu for 1 specific custom list RRS feed

  • Question

  • I want to hide "Delete Item" from ECB menu for 1 specific custom list. I can not change or copy master page or create any custom page.

    Can I do it thru jquery/javascript or creating simple action ?

    Please advise

    Thursday, April 29, 2010 4:44 PM

Answers

  • The ECB menu is built when a user clicks on the list item and is based on a hidden table on the page that contains all ECB menu items. To hide a menu item, just find the correct row of the table and remove it.



    Code Snippet

    <script type="text/javascript">

    var elemTable=document.getElementById('ECBItems');

    if (elemTable !=null) {
        var elemTBody=elemTable.childNodes[0];

    //iterate each table row to find the correct ECB menu item to hide(remove)

       for (var iMenuItem=0; iMenuItem < elemTBody.childNodes.length; iMenuItem++) {
            var elemTR=elemTBody.childNodes[iMenuItem];
            var elemTDTitle=elemTR.childNodes[0];
            var title=GetInnerText(elemTDTitle);

     //here we filter on title, but the table contains more information if need be

            if(title =='Preview') {
                elemTBody.removeChild(elemTR);
            }
        }
    }

    </script>

     

    http://www.chakkaradeep.com/post/SharePoint-Hiding-Menu-Items-from-the-Edit-Control-Block.aspx

     

    hope this helps

    • Proposed as answer by Anisree Wednesday, May 5, 2010 6:34 AM
    • Marked as answer by Lily Wu Friday, May 7, 2010 6:28 AM
    Friday, April 30, 2010 4:20 AM

All replies

  • The ECB menu is built when a user clicks on the list item and is based on a hidden table on the page that contains all ECB menu items. To hide a menu item, just find the correct row of the table and remove it.



    Code Snippet

    <script type="text/javascript">

    var elemTable=document.getElementById('ECBItems');

    if (elemTable !=null) {
        var elemTBody=elemTable.childNodes[0];

    //iterate each table row to find the correct ECB menu item to hide(remove)

       for (var iMenuItem=0; iMenuItem < elemTBody.childNodes.length; iMenuItem++) {
            var elemTR=elemTBody.childNodes[iMenuItem];
            var elemTDTitle=elemTR.childNodes[0];
            var title=GetInnerText(elemTDTitle);

     //here we filter on title, but the table contains more information if need be

            if(title =='Preview') {
                elemTBody.removeChild(elemTR);
            }
        }
    }

    </script>

     

    http://www.chakkaradeep.com/post/SharePoint-Hiding-Menu-Items-from-the-Edit-Control-Block.aspx

     

    hope this helps

    • Proposed as answer by Anisree Wednesday, May 5, 2010 6:34 AM
    • Marked as answer by Lily Wu Friday, May 7, 2010 6:28 AM
    Friday, April 30, 2010 4:20 AM
  • Hi,

    I want to @@hide "Delete" from ECB menu for 1 specific document library@@........I put above script in master page, but it gives no result. Where shall i put this script, can you elaborate more..!!????

    Friday, June 15, 2012 11:12 AM
  • Hi Rahul,

    If you want to hide the ECB menu from specific list then you can add the below snippet in the /Allitems.apx page of that list.

    Add the below code block in Content place holder section as shown below:

    <asp:Content ContentPlaceHolderId="PlaceHolderPageDescription" runat="server">
    <script type="text/javascript" src="../../SiteAssets/Scripts/jquery-1.6.2.min.js"></script>

    <script type="text/javascript">


    $('.ms-MenuUIPopupBody').live('mouseover', function() {         
    $("#ID_DeleteItem").hide();  //if list use "#ID_DeleteItem" if library use "#ID_DeleteDocItem"

             });

    </script> 


    </asp:Content>


    MCTS- Please mark posts as answered where appropriate.



    Thursday, June 28, 2012 8:05 AM
  • Hi Nadim,

    Can we do the same functionality when the ECB pop up menu loads? The above code hides the delete item only when the mouse is hovered. It is shown to the user when the pop is opened.

    Thanks


    Monday, July 9, 2012 11:42 AM
  • Hi Rakesh, 

    You can try using different event (load or click), to hide the ECB delete item.


    MCTS- Please vote and mark posts as answered where appropriate.

    Tuesday, July 17, 2012 6:46 AM
  • Same code is not working for SharePoint 2013 any idea?

    Regards,
    Bijay
    SharePoint MVP, India
    Twitter | Facebook | LinkedIn
    EnjoySharePoint.com | OnlySharePoint2013.com

    Sunday, April 5, 2015 10:41 AM
  • we can hide the ECB menu items for the delete item, we need to place the below code in the content editor webpart

    <style type="text/css">

    li[text="Delete Item"] {
          display: none;
        }

    </style>if user want to hide remaining menu items have to assign the name to text.



    Thursday, June 15, 2017 8:32 AM
  • We can hide the ECB menu items by using the below script for the "Delete Item", we need to write the below script in the content editor webpart.

    <style type="text/css">

    li[text="Delete Item"] {
          display: none;
        }
    </style>

    If user want to hide "Edit Item", "view Item" or any menu items in ECB, have to assign the menu item in the text in the above script

    Thursday, June 15, 2017 8:41 AM