Click here to Skip to main content
15,881,812 members
Articles / Programming Languages / Javascript

SharePoint Customization Tricks - Part 1

Rate me:
Please Sign up or sign in to vote.
4.00/5 (5 votes)
18 Jan 2009CPOL2 min read 99.6K   197   26  
Trick #1: Hiding the list view toolbar menu items!
hideListViewToolbarItems("Edit in Datasheet",
	"export to Spreadsheet","view rss feed","settings:create view");
	


	function hideListViewToolbarItems()
	{
	 /// <summary>
         /// By : Ayman M. El-Hattab ( ayman.elhattab@gmail.com )
         /// http://ayman-elhattab.blogspot.com        
         /// You can use this function to hide any menu items rendered in the ListViewWebPart toolbar
         /// which is used in the list view pages, Just call the function and pass the menu item
         /// names ( comma separated ) as they appear in the toolbar.
         /// Only one exception to that when you need to hide "Create View" which appears twice
         /// one in  "List Settings" and the other one in the view selector, in order to resolve this 	 /// conflict just call the function as follows :
         //  hideListViewToolbarItems("settings:create view")
         /// or hideListViewToolbarItems("view:create view").
         /// Kindly note that the arguments are case Insensitive         
         ///     
         /// </summary>
		
		var menuItem;	
		var menuItemName;
		var menuItemIndex=-1;
		var menuItemNames=new Array("edit in datasheet",
		"open with windows explorer","connect to outlook",
		'export to spreadsheet','view rss feed','alert me'
		,"create column","settings:create view","list settings",
		"document library settings","explorer view","all documents",
		"all items","modify this view","view:create view",
		"new document","new item","new folder","upload document",
		"upload multiple documents");
		var menuItems = new Array("EditInGridButton",
		"OpenInExplorer","OfflineButton",
		"ExportToSpreadsheet","ViewRSS","SubscribeButton"
		,"AddColumn","AddView","ListSettings",
		"ListSettings","View1","DefaultView",
		"DefaultView","ModifyView","CreateView",
		"New0","New0","NewFolder","Upload",
		"MultipleUpload");		
		var allMenuItems = document.getElementsByTagName('ie:menuitem');
			for(var i = 0; i < hideListViewToolbarItems.arguments.length; i++ ) 
			{								
				menuItemName= hideListViewToolbarItems.arguments[i].toLowerCase();								
								
					for (j=0;j<menuItemNames.length;j++) 
					{
						if(menuItemNames[j]==menuItemName)
						{				
							menuItemIndex = j;
							break;
						}
					}
					
					menuItem=menuItems[menuItemIndex];
					
					for (var l = 0; l < allMenuItems.length; l++)
					{		
						if(menuItemName.indexOf(":")!=-1)
						{
							menuItemName = menuItemName.split(":")[1];
						}
						if (allMenuItems[l].id.indexOf(menuItem)!=-1 && allMenuItems[l].text.toLowerCase() == menuItemName )
						{		
							// For FireFox Compatibility
							var parentNodeOfMenuItem = allMenuItems[l].parentNode;
							parentNodeOfMenuItem.removeChild(allMenuItems[l]);
						}
					}
				
				
			}
	}
	

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Egypt Egypt
Ayman El-Hattab is a Regional Technology Solution Professional focusing on helping software professionals and organizations build better SharePoint Solutions using Microsoft Application Lifecycle Management (ALM) technologies and tools. Ayman has been in this role since 2010 and has presented at many conferences all over the Middle East & Africa about ALM, SharePoint, C#, asp.net and Business Intelligence technologies. Ayman is also a Microsoft Most Valuable Professional [SharePoint MVP] , ALM Ranger, published author and an enthusiastic speaker who enjoys working with the online and offline developer communities all over the world. Ayman is the founder of MEA ALM Community & SharePoint4Arabs, community lead at Egypt SharePoint User Group and an organizer of several SharePoint Saturday events. Outside of work, Ayman can be found watching soccer games, playing xbox or watching documentary movies.

Comments and Discussions