Display ribbon on page with multiple ListViewWebPart


Hello everyone,

Today I’ll talk about a code snippet I found for a discussion on msdn. (see the discussion here: http://social.msdn.microsoft.com/Forums/en/sharepoint2010programming/thread/0372bae3-6e10-4b1f-a77a-49c892086538)

The person wanted that the behavior of a standard ListViewWebPart list remains the same even if we added other webparts on the page.

After some research I came across this tip:

http://stackoverflow.com/questions/4848892/list-tools-tab-is-no-longer-available-after-adding-webpart-to-the-page?answertab=oldest#tab-top

The proposed answer is to add a script in the page simulating a click on the ListViewWebPart.

Here’s the script:


setTimeout(function() {
    var elem = document.getElementById("MSOZoneCell_WebPartWPQ2");
    if(elem != null) {
        var dummyevent = new Array();
        dummyevent["target"] = elem;
        dummyevent["srcElement"] = elem;
        WpClick(dummyevent);
    }
}, 2000);

I tested it successfully on a team site by adding this code into a Content Editor Web Part on the page. I just changed the timeout to 2 so that it goes faster.

Well done to the person who found it!

Christopher

Advertisements
This entry was posted in SharePoint 2010 and tagged , , . Bookmark the permalink.

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