문제

I have a scenario where I need to create an application page that is installed to the ECB menu of a specific list only. Is this possible? or is the only way to do it associating the elements file with a list type e.g. task list?

도움이 되었습니까?

해결책

Yes it is possible to do that: create ECB items menu only for a list....and even better decide at runtime how many items to put in the ECB menu. For this you need javascript skills.

SharePoint give us some hooks to add custom ECB items using javascript. This hook is the js function: Custom_AddListMenuItems(m, ctx). But the problem is how to add dynamic items in the ECB right ? The solution I've used was to implement a synchronous Ajax call to a custom aspx which returns a xml with items and their actions. Here is the code:

<script language="javascript">

function Custom_AddDocLibMenuItems(m, ctx)
{    
  //debugger;

  var request;
  var url = ctx.HttpRoot + 
      "/_layouts/GetCommands.aspx?ListID=" + ctx.listName + 
      "&ItemID=" + currentItemID + 
      "&UserId=" + ctx.CurrentUserId + 
      "&DateTime=" + Date();

   if ( window.XMLHttpRequest )
   {
      request = new XMLHttpRequest();
      request.open("GET", url, false);
      request.send(null);
   }
   else if ( window.ActiveXObject )
   {
      request = new ActiveXObject("Microsoft.XMLHTTP");
      if ( request )
      {
         request.open("GET", url, false);
         request.send(); 
      }
   }

   if ( request )
   {   
      var commands = request.responseXML.getElementsByTagName("Command");
      // for each command found in the returned XML, extract the name, 
      // image Url and script, and a new menu item with these properties
      for ( var i = 0; i < commands.length; i++ )
      {
         var cmdName = commands[i].getElementsByTagName(
            "Name")[0].firstChild.nodeValue;
         var imageUrl = commands[i].getElementsByTagName(
            "ImageUrl")[0].firstChild.nodeValue;
         var js = commands[i].getElementsByTagName(
            "Script")[0].firstChild.nodeValue;
         var addSep = commands[i].getElementsByTagName(
            "AddSep")[0].firstChild.nodeValue;

         CAMOpt(m, cmdName, js, imageUrl);

         if (addSep == "True")
            CAMSep(m);
      }

      // if at least one command was actually added, add a separator
      if ( commands.length > 0 )
         CAMSep(m);
   }

   // returning false makes SharePoint render the rest of the standard menu
   return false;   
}

function Custom_AddListMenuItems(m, ctx)
{
    Custom_AddDocLibMenuItems(m, ctx);
}
</script>

This script must be placed in a webpart next to the list webpart (in a Content Editor Web Part for ex.)

The idea is not mine, here is the original article. Hope this will help.

다른 팁

It must be attached to a list template (if you are using the server side features), that has a specific id. I recommend that you create a feature with a hidden list template and list instance and then attaches your ECB to that list template.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top