This is a short one on how to remove menu items from the “New”, “Actions”, “Settings”, and “List view’s” menu in a list or document library.
This method requires a CEWP added below the list view web part with the code, and is a “per view code” which must be added to every view where the menu items shall be removed.
I will first give a list of the “names” of the “standard” elements found in the list view toolbar menu and list view menu, then i will give an example of how to remove selected items from the menu’s.
The menu items in the “Actions”, and the “Settings” menu has these “names” (the part of the ID used to locate them):
- _EditInGridButton
- _ExportToSpreadsheet
- _ExportToDatabase
- _ViewRSS
- _SubscribeButton
- _AddColumn
- _AddView
- _ListSettings
The “New” menu (the one containing all the “New-button” for all your content types) uses “_New0” for the first “_New1” for the next and so on.
The “view’s” menu uses these names for the “standard” menu items:
- _DefaultView
- _ModifyView
- _CreateView
The custom made views uses the “DisplayName” of the view to identify it.
Code for hiding elements in “New”, “Actions”, “Settings” and “View’s” menu:
<script type="text/javascript" src="/test/English/Javascript/jquery-1.3.2.min.js"></script> <script type="text/javascript"> /* Hide menu items in list view toolbar and views in view selector * --------------------------------------------- * Created by Alexander Bautz * alexander.bautz@gmail.com * https://spjsblog.com * v1.0 * LastMod: 26.11.2009 * --------------------------------------------- * Include reference to: * jquery - http://jquery.com * --------------------------------------------- */ // Remove menu items - in this example all items in the "Settings" menu are removed (and therefore the menu is removed) // This is the array of menu items to hide var arrOfMenuItemsToHide = ['_EditInGridButton','_AddView','_AddColumn','_ListSettings']; $.each(arrOfMenuItemsToHide,function(idx,item){ $("*[id$='" + item + "']").next().andSelf().remove(); }); // Views - hides "Modify", "Create" and the custom made "My Test View" // This is the array of view's or to hide var arrOfViewsToHide = ['_ModifyView','_CreateView','My Test View']; $.each(arrOfViewsToHide,function(idx,item){ $.each($("*[id$='_ViewSelectorMenu']").children(),function(){ if($(this).attr('id').match(item) || $(this).attr('text')==item){ $(this).next().andSelf().remove(); } }); }); // Remove the menu if all menu items are removed $(".ms-menutoolbar").find('menu').each(function(){ if($(this).children().length==0){ $(this).parents('td.ms-toolbar:first').prev().andSelf().remove(); } }); </script>
The jQuery-library is found here. The sourcecode refers to jquery-1.3.2.min. If you download another version, be sure to update the script reference in the sourcecode.
This code can be adapted to hide elements based on group membership of the logged in user. I have written about a method to get the group collection for a user and to verify group membership here Showing or hiding list fields based on membership in a SharePoint group.
Ask if something is unclear.
Regards
Alexander