Display ribbon when multiple ListViewWebPart on the page


Hello everyone,

Some time ago I wrote about a script to display the ribbon on the pages where several ListViewWebPart were present (see here).

The idea of ​​this script was to simulate a click on a ListViewWebPart to view the ribbon. However, it seems JavaScript function “WPClick” used in SharePoint 2010 does not work correctly on 2013!

To simulate clicking on the Web, we must now use the following script.



ExecuteOrDelayUntilScriptLoaded(ShowContextRibbonSections, "sp.ribbon.js");

function ShowContextRibbonSections(){

    var initInfo = {

          editable: true,isEditMode: false,allowWebPartAdder: false

    };

    SP.Ribbon.WebPartComponent.registerWithPageManager(initInfo);

    var wpcomp = SP.Ribbon.WebPartComponent.get_instance();

    if(wpcomp){

         var zc = document.getElementById("MSOZoneCell_WebPartWPQ2");

         wpcomp.selectWebPart(zc, true);

    }

}

This new script was found by a member of the msdn forums: http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/c4c988e2-805c-49a4-a5bf-5097dedcef58

Thank Peter Azure for this tip!

Christopher

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s