Hide menu items in list view toolbar and views in view selector

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

69 Comments on “Hide menu items in list view toolbar and views in view selector

  1. Hello,

    thanks for this, you do great job with javascript and sharepoint. But i have a litle problem, this script requires Jquery 1.3.2 and on my page, i need to refer another script with the Jquery 1.2.6 .
    So do i have to do a choice between the two script? or can i refer Jquery 1.3.2 AND 1.2.6 on the same pages..i don’t know..

    1. K, so I played a but and this is what i came up with. I was able to hide each item on the Form tool bar. I have tested these individually, not together. But was successful. Any suggestions for better code is welcomed

      <script type="text/javascript" src="/sites/learning/Scripts/jquery-1.3.2.min.js"></script>
      <script type="text/javascript">
      //Hide toolbar
      $('table.ms-toolbar:first').hide();
      //remove toolbar labels
      $('td.ms-toolbar:nth-child(2)').hide();
      //removes New Item, Icon
      $('td.ms-separator:nth-child(2)').hide();
      $('table.ms-toolbar td..ms-toolbar:first').hide();
      //removes Edit Item, Icon and seperator
      $('td.ms-separator:nth-child(2)').hide();
      $('td.ms-toolbar:nth-child(3)').hide();
      //removes Delete Item, Icon and seperator
      $('td.ms-separator:nth-child(4)').hide();
      $('td.ms-toolbar:nth-child(5)').hide();
      //removes Manage Perm, Icon and seperator
      $('td.ms-separator:nth-child(6)').hide();
      $('td.ms-toolbar:nth-child(7)').hide();
      //removes Workflows, Icon and seperator
      $('td.ms-separator:nth-child(8)').hide();
      $('td.ms-toolbar:nth-child(9)').hide();
      //removes Alert Me, Icon and seperator
      $('td.ms-separator:nth-child(10)').hide();
      $('td.ms-toolbar:nth-child(11)').hide();
      //removes Version Hist, Icon and seperator
      $('td.ms-separator:nth-child(12)').hide();
      $('td.ms-toolbar:nth-child(13)').hide();
      </script>
      
    2. Hi Larry –

      I pasted your code in a CEWP underneath my list DispForm because I just need to remove the New menu option from the toolbar. Other than pasting the code and having the jquery versions match, is there anything else I need to do? Because I still see the New menu option…

      Any help will be really, really appreciated!

      – Tracey

    3. Hi Larry – me again!

      I fixed my ‘problem’. I did not have the correct path to my jquery file…

      Larry, I appreciate your code – it is very adaptable to different types of situations and crazy useful!

      – Tracey

    1. Got it now. You can disable the attachment ability from “List settings”. The spelling button must be identified by some ID, but I’m on WSS and do not have a MOSS portal to check the ID.

      Download IE Dev Toolbar or use Firefox with FireBug to identify the element and the use:

      $("#TheIdOfTheField").hide();
      

      Alexander

  2. Alexendar

    I tried following but nothing is working, am I missing anything?

    
    

    $(“ctl00_m_g_34d73359_815e_4208_84da_4240ad68e372_ctl00_ctl01_ctl00_toolBarTbl_RptControls_ctl01_LinkText”).hide();

    [/endsourcecode]

    1. To hide the attachment link:

      <script type="text/javascript" src="../../Javascript/jquery-1.3.2.min.js"></script>
      <script type="text/javascript">
      $("a[id$='Attach_LinkText']").parents('table:first').hide();
      </script>
      

      Alexander

    1. I’m sorry, but i do not have a MOSS portal before me to check it for you. WSS does not have this spell-check feature.

      See comment above regarding IE Dev Toolbar or FireBug. With one of these you could check it yourself.

      Alexander

  3. Alexendar,

    Do you have any nifty tricks to delete all the items in a list in a quick manner. I delete about 40K items in one list every week and need a faster way of doing instead of using SSIS or removing the list (that is not an option)

  4. Hi,

    I want to hide “Add to My links” item from “Actions” menu.
    I know how can I remove it from a subsite or from a doc or list library.

    I have used below java script to remove it,

    function GetElementByText(tagName, title)
    {
    var a = document.getElementsByTagName(tagName);
    for (var j=0; j < a.length; j++)
    {
    if (a[j].text)
    {
    if (a[j].text === title)
    {
    return a[j];
    }
    }
    }
    return null;
    }
    function hideAddMyLinks()
    {
    var q = GetElementByText("ie:menuitem","Add to My Links"); if (q)
    {
    q.hidden= true;
    }
    }
    _spBodyOnLoadFunctionNames.push("hideAddMyLinks");

    But if I am using this code I am able to hide it from single library.
    I want to hide “Add to my links” from all the sub sites in a site collection.

    Please suggest your quick help will be much appreciated.

    Thanks,
    SP~

  5. In hopes that other people find this resource as helpful as I have, I’ll add a bit about document libraries as well. This nifty trick works here too and can really make life easier than other options to tweak doc libs. Some specific fields you might want to get rid of:

    Uploads: “Upload” = _upload, “Upload Multiple Documents” = _MultipleUpload

    Views: All the view names you might want to remove from an OOtB view list are as follows –
    ‘_ModifyView’,’_CreateView’,’All Documents’,’Explorer View’,’Merge Documents’,’Relink Documents’

    1. Not quite sure what happened with the spacing there but in the view names, those should be single spaces. If you select that entire string, just double check it works for you.

  6. Hi there –

    Anyone happen to have a way to change the URL of the ‘New” button in a list form page? I would like it to go to a custom page rather than open the typical New Item Form. And iof it could be done in a CEWP, I would be insanely happy!

    1. Hi,
      You know you can do this in SharePoint Designer? Right click on the list > Properties > Supporting Files. Select your modified form and click “Apply”.

      Alexander

  7. Can we also add items to the View List menu? I would like to create a view with a dymanic value. If i could add this option to the view menu for users would make it a little seemless for them.

    Is this somethign fairly easy to do? Maybe even replace a list item with a new name and URL (link)

    1. I’m not quite sure how you would use this. The view menu reflects the current views a defined in the “views collection” for that list. You can not add a custom menu item without having an existing view to link to.

      If it is the view name as displayed in the menu, this would be fairy easy to change.

      Alexander

  8. Anyone know how to change the URL of the ‘Upload’ button as well as the links under its dropdown? I would like to have the user directed to a custom upload page with ‘Overwrite existing files’ unchecked by default.

    Thanks in advance.

  9. I’m using only the views code to hide only the views menu. But the views code is hiding the complete menu bar. Am I using it right or am i missing something. I want to hide only the views selection.

    Thanks

  10. Hi,

    I am trying to display different default views for my document library based on which user group the user belongs to.

    For example, an admin user gets to see additional columns which other users will not see.

    Is this possible?

    many thanks,

    Anu

  11. Hi Team,

    Can you please let me know what is wrong with my Form Teamplates ? Because i did the same thing… Also I have checked the Jquery is called ok.
    Still when i add this script in my content editor it’s nothing happen.

    all such items are visible as it is. any idea ? any reference ?

  12. Hi,
    In addition of above post,

    you mentioned var arrOfViewsToHide = [‘_ModifyView’,’_CreateView’,’My Test View’] it means should i need to replace ‘_ModifyView’, ‘_CreateView’ & those to my sharepoint listed id ? or should i need to keep that as it is ?

    Moreover if i need to replace then what id i need to use there td has id, also control has it’s server id and other 2-3 id fileds around.

    Can you guide me little more please ?

    1. Hi, Only “My Test View” should be changed to match any custom made view.

      Please note that this was made for SP2007 and has not been tested with SP2010.

      Alexander

  13. Hi Alexander Bautz (Rather i should say you master),

    Your tips works. It’s above the list and because of that it’s not working.
    But now, Can you tell me how can i remove “All Documents”, “All Items”, “All Forms” & “Explore View” ?

    I guess it’s better i use this form rather than msdn while need a quick answer.

    Regards,
    Brijesh Shah

  14. Hi Sir,

    I did it. Now can you tell me one more thing ?
    I have one list of assignment where we got the new assignment daily. Now, there we have field called “Assigned To”.

    Now i need to check that field and that field may has one ore more users exist based on assignment.

    Now, Based on roles or group or permission i need to hide/ show this menu.
    Like me as a developer group i should not have such view access or add menu access but only have access to view “My Assignment” else My lead has all view access.

    Can you guide me somewhat in this area ? I read your this article
    https://spjsblog.com/2009/09/20/showing-or-hiding-list-fields-based-on-membership-in-a-sharepoint-group/

    which is very much close to that but still need help from expert.

  15. Hi Master,

    Sorry to disturb you again.
    But your Javascript is working fine for me in Document library. but not in custom list or Task where we have defaultly having multiple views like “Active Tasks”, “All Tasks”, By Assigned To”, “By My Groups”, “Due Today”, “Create View”.
    Can i have the actual name of these all ? Or can you just check by creating one Task in the Sharepoint Please ?

    Please let me know your thoughts on this, because it’s really helps me.

  16. on hiding the menu items for the display form, the script is working for IE, but not for Google Chrome…all the options are still showing. Anyone know why that might be happening?

  17. I was referring to the code that was give to hide menu items (edit, delete, workflow, etc) in the dispitem form. Sorry I wasn’t more clear.

  18. Hello Alexandre,

    Great Blog ! Very useful !!
    I’m able to hide some views in the view selector with the above code. Here is an easy one I hope. How do I select a specific view among those which are left ? Or modify the default view ?

    thanks

    1. Let’s say after removing some views I have left : ‘_CreateView’, ‘TestView1’ (which is the default view) and ‘TestView2’.
      Depending on who is logged in I would like to display the list with ‘TestView2’. I followed your other guidelines for user ID identification and it works. But how can I force/select with javascript ‘TestView2’ ?
      I hope it’s clearer now
      thanks in advance

    2. Thanks for your patience and the suggestion, however my url is static. If I take your code, what I’m looking for is more a piece that would imitate something like :
      var viewToShow = [‘TestView2′];
      $.each(viewToShow,function(idx,item) {
      $.each($(“*[id$=’_ViewSelectorMenu’]”).children(),function() {
      if($(this).attr(‘id’).match(item) || $(this).attr(‘text’)==item) {
      $(this).next().andSelf().?selectView?();
      }
      });
      });

      I guess the code could be written with just one line, I don’t need a loop obviously for the view to display is unique. Is this possible ?
      Marc

      1. If you want to redirect the user to “TestView2” you could just redirect to the viewURL – there is no need to get it from the view selector – just use javascript and write: location.href=L_Menu_BaseUrl+”/”+TestView2.aspx

        Or am i missing something?

        Alexander

  19. Hiding View’s items is working fine in IE, but not in Firefox 3.x. Does anybody know what needs to be changed in the JS to get this functionality also working in Firefox ? Is it actually possible ?
    thanks in advance

    1. Hi,
      I have tested it in Firefox 5 and it works. I do not have access to Firefox 3.x at the time, but it probably has to do with Firefox 3.x handling “children” in a different way. Try alerting the “children.length” and see what you can find.

      Alexander

    2. Thanks Alexander,

      Not sure what I did wrong, but anyhow I got it finally running on Firefox 3.x with the original scripts.

      regards

      Marc

  20. Hi Alexander,
    Do you know of any jquery scripts to hide menu item(s) on the item display form? I am in a situation where I have to give a group of people rights to edit items, but I do not want them starting or cancelling workflows manually, so I would like to hid that menu option when the display the item. Any help would be appreciated.

    1. Hi,
      The approach is a bit different between SP2010 and SP2007

      For English language SP2007 use something like this:

      $("table.ms-toolbar").find("a[title='Workflows']").parents('table:first').parent().next().andSelf().remove();
      

      And for SP2010 something like this:

      $("#s4-ribboncont").find("a[id*='Workflows']").parents('span.ms-cui-row').remove();
      

      Alexander

  21. I cannot get this to work on the views. Even straight cutting and pasting works on the settings menu but the views remain unchanged (Modify, Create, and My Test View, all still show.)

    I am on MOSS 2007 and jquery 1.7.1 and IE9. Any ideas? This script would be a godsend if I could get it to work. >:(

    1. Thanks for the reply. Looks like its something with the browser. Chrome/Firefox hides the Create and Modify views correctly (misses ‘My Test View’.) IE9 seems to miss hiding all the views.

  22. Pingback: view
  23. Hello, I have a similar need to remove a menu item on the ‘Content Type’ menu but by user group. Here is the senario…

    I will have 2 SP ‘Members’ groups. Group 1 is MembersAP, group 2 is MembersPlant.
    I will have 2 added content types of ‘APOnly’ and ‘Plant’. These content types will have different fields.

    I need the user group ‘MembersPlant’ to NOT see the ‘APOnly’ content type.

    How can I use your java scripts to ‘hide’ the ‘APOnly’ content type menu item for the group ‘MembersPlant’?

    Thanks for the great blog!

  24. Hello Alexander

    Is is possible to hide the individual column filters on each of the columns in a list (i.e, the ones which appear below the “new”, “actions”, “settings” toolbar) so that it is still possible to sort columns for the displayed data but not possible to filter the data or clear existing filter (or perhaps prevent the little “open menu” from opening when you hover over the downward pointing arrow on the right side of each column).

    Thanks!

    Dave

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.