Scenario: Show menu item in SharePoint ECB based on a condition e.g when versioning is enabled in the List or Document Library.
Solution: This can be done by creating a delegate control.
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Control Id="AdditionalPageHead"
Sequence="90"
ControlSrc="~/_CONTROLTEMPLATES/NY.ExportVersionHistory/ECBDelegateControl.ascx" />
</Elements>
In the ascx control we need to define Custom_AddListMenuItems(m, ctx) and Custom_AddDocLibMenuItems(m, ctx)
<script type="text/javascript">
function Custom_AddListMenuItems(m, ctx) {
AddECBMenuItems(m, ctx);
}
function Custom_AddDocLibMenuItems(m, ctx) {
AddECBMenuItems(m, ctx);
}
function AddECBMenuItems(m, ctx) {
var pageUrl = ctx.HttpRoot + "/_layouts/NY.ExportVersionHistory/ExportVersionHistory.aspx?ID=" + currentItemID + "&List=" + ctx.listName;
if (ctx.verEnabled) {
CAMOpt(m, "Export Version History", "window.open('" + pageUrl + "');", "/_layouts/images/NY.ExportVersionHistory/Excel_Small.png");
CAMSep(m);
}
}
</script>
0 comments
Post a Comment