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
Thanks for this!
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..
Ok i just want to said thanks and it works with Jquery 1.2.6 !
can this be adopted for list forms? say DispForm hiding pieces of the tool bar, EditItem, deleteitem?
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
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
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
How can I hide Attach/Spelling from newform.aspx
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:
Alexander
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]
To hide the attachment link:
Alexander
Thanks
Can you please also let me know the id of “Spelling” and its icon?
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
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)
Hi,
No, i have not, but you should look into how this could be done with powershell. Powershell is very versatile and powerful. I do not have any code for you, but take a look here:
http://blogs.flexnetconsult.co.uk/colinbyrne/2008/02/26/PowerShellSharePointThreeWaysToDeleteAListItemIDCAMLStringMatching.aspx
Alexander
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~
Hi,
To do this for all sites, you would have to add it to the master page. Though i have not tested this solution myself, i think this solution from Muhimbi would be something to look at: http://muhimbi.com/Products/SharePoint-Infuser-(Free).aspx
Alexander
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’
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.
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!
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
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)
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
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.
Hi,
Look here Manipulate upload link in document library
Alexander
How can I change the name of the upload menu? I cannot find an attr for it.
I found the way, sorry for the Newbie question:
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
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
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 ?
Hi,
Ensure the CEWP is placed below the list view webpart.
Alexander
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 ?
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
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
Hi,
Try using the “Display Name” of the menu item.
Alexander
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.
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.
Hi,
I’m not quite sure what you are asking here. Could you please clarify?
Alexander
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?
I’m not sure what you mean by display form. What are you hiding?
Alexander
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.
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
Hi, I’m not quite sure what you mean. If you want to hide a “user made” view you use it’s display name.
Alexander
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
Hi,
Look at this comment regarding something similar:
https://spjsblog.com/2009/11/05/requests/comment-page-2/#comment-678
Alexander
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
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
Sorry, I didn’t reply in the right way.
The solution works fine like that, thank you a lot
Marc
Thanks a lot Alexander, the redirection script is OK.
Marc
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
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
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
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.
Hi,
The approach is a bit different between SP2010 and SP2007
For English language SP2007 use something like this:
And for SP2010 something like this:
Alexander
You’re the bomb Alexander, it worked perfectly!
I see how you removed the control but what if I wanted to add a button after the work flow button how would I do it?
SharePoint 2007 or 2010?
Alexander
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. >:(
Try using jQuery v1.6.4. I guess that version should work.
Alexander
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.
FYI – had to return to jquery 1.3.2 to make this script work. Thanks!
Is there a 2010 version of this code available?
Thanks.
Alexander, could you please adopt for SP2010? Thank you very much !
Anyone know how to hide views on the view selector for 2010? I tried Alex’s code but it gives me a javascript error.
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!
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