Thursday, December 23, 2010

Adding Context Menu in SharePoint List or Library using Content Editor Web part

< script type="text/javascript">
function Custom_AddListMenuItems(m, ctx) {
CAMOpt(m,'Edit Form(new window)','javascript:window.open(\'EditForm.aspx?ID=' + currentItemID + '\');','/_layouts/images/LIST.GIF');
// false means that the standard menu items should also be rendered
// if you set true, it will show only the menu which you added( standard sharepoint menu items will not be available.
// you can control by setting the value of true or false
return true;
}
</script>

If the above function returns false, then the context menu is displayed as below.




If the above function returns true, then the context menu is displayed as below.



Similary if you want to do for List, you have to use the Different method name.

For Document Library : Instead "Custom_AddDocLibMenuItems"

For List : "Custom_AddListMenuItems"

Also you can do following using Script in Content Editor Webpart

To hide the "Delete" (particular) menu item in LibraryContext Menu add this below function

function CAMOpt(p,wzText,wzAct,wzISrc,wzIAlt,wzISeq,wzDesc)
{
var mo=CMOpt(wzText,wzAct,wzISrc,wzIAlt,wzISeq,wzDesc);
if(!mo)return null;
//wzText you can give which one you want hide (like "Edit Properties")
if(wzText != "Delete") AChld(p,mo);
return mo;
}

You can download the script and add it in your content editor webpart; it will take care of the previous actions for document Library.

Use the approriate Script for list / library.
Enjoy!!!...

0 comments: