简体   繁体   中英

Custom Action for specific list view - SharePoint 2010

How can I target custom ribbon action menus for specific list views? I want to be displayed in the default view of the list but to be hidden in the other views.

Any ideas?

Though the question is old, yet unanswered , I am responding to it. Create an empty Sharepoint Project in VS2010 , add an Elements.xml file in the project and past following XML in it.

    <CustomAction Id="MyCustomButton" Sequence="999"
                      GroupId="Manage"
                      Location="CommandUI.Ribbon" // Location to display button
                      RegistrationId="101" // on every list, for  a specific list or library put the GUID of list here e.g. RegistrationId="{GUID_OF_LIST}"
                      RegistrationType="List"
                      Rights="ManageWebs"
                      Title="Custom Document Library Button">
            <CommandUIExtension>
                <CommandUIDefinitions>
                    <CommandUIDefinition Location="Ribbon.Documents.Manage.Controls._children">
                        <Button Id="Ribbon.Documents.Manage.Controls.CustomButton" TemplateAlias="o1"
                                ToolTipDescription="Creates a server side action."
                                ToolTipTitle="SSRibbon" LabelText="SS Action"
                                Image32by32="/_layouts/images/ContractClaims/newproject.jpg"
                                Image16by16="/_layouts/images/ContractClaims/newproject.jpg" Alt="New Project"
                                Command="{3E04C0C1-12DD-449E-905F-7E88EB9E22B1}"
                                Sequence="20"/>
                    </CommandUIDefinition>
                </CommandUIDefinitions>
                <CommandUIHandlers>
                    <CommandUIHandler Command="{3E04C0C1-12DD-449E-905F-7E88EB9E22B1}"

                                     CommandAction="javascript:alert ('Hello World' ) ;" />
                </CommandUIHandlers>
            </CommandUIExtension>
        </CustomAction>

The several locations to display the button can be found here .For more on the top you can google respective XML elements.

You can use EnabledScript parameter in CommandUIHandler , where you can put javascript code and check if specific page/list/view is loaded.

link to similar answer

Example:

<CommandUIHandler 
  Command="Ribbon.ListItem.CustomGroup.Controls.BtnSayHello.Command"
  CommandAction="javascript:alert('Hello');"
  EnabledScript="javascript:
    function isEnable(){
      if(location.href.indexOf('AllItems.aspx') > 0){
        return true;
      }
      return false;
    }
    isEnable();"
/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM