A question came up about how to go about hiding list action menu items on SharePoint lists. There were some actions that either didn’t make sense for their extranet users or they didn’t want to support.
For example they would like to hide the “Edit in Datasheet” and “Alert Me” buttons.
A number of people have posted different types of solutions. Some requiring development, some recommending editing core.js, but the solution I liked the best was a bit of Java Script that could be deployed for a single list with a content editor web part or called from a master page if the desired results were more global.
The script was written by Ayman El-Hattab and posted on his blog. When I first deployed it in a CEWP it wasn’t working. I suspected that it was not running last and therefore not overriding the script used to create the links. Talking with Ricky Spears confirmed this. He had run into the same thing when trying to add JavaScript in SharePoint pages. SharePoint has a list of JavaScripts that fire after the page loads. He showed me how to add our script to the end of that list. More info on adding JavaScript can be found in this post.
Here’s how we get ours to load last:
// Our script needs to run last
_spBodyOnLoadFunctionNames.push(“hideListActions”);
function hideListActions() {
// Add menu items by name, separated by commas
hideListViewToolbarItems(“Edit in Datasheet”, “Alert Me”);
}
Here is the entire script:
// Our script needs to run last
_spBodyOnLoadFunctionNames.push(“hideListActions”);
function hideListActions() {
// Add menu items by name, separated by commas
hideListViewToolbarItems(“Edit in Datasheet”, “Alert Me”);
}
function hideListViewToolbarItems()
{
/// <summary>
/// By : Ayman M. El-Hattab ( ayman.elhattab@gmail.com )
/// http://ayman-elhattab.blogspot.com
/// </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]);
break;
}
}
}
}
Here is the resulting list actions menu:
Thanks Ayman for a nice script and thank you Ricky for your help too!
I am sure there are other good ways to accomplish this. Please share them in the comments.