Bring back the missing list tools menu in list view with multiple webparts

In my latest project I added a web part to a list view and needed to have the list tools visible. I had to look for a fix to the disappearing list tools menu.

Yes you can bring it back by clicking the web part you want to focus on, but it will be hidden initially if there are more than one web part in the page.

I digged into the sp.ribbon.js and found the “WpClick” function. Knowing that this function is called upon click on a web part, it was only a matter of finding a way to call it by code when the page loaded.

The parameter passed to the function is a click-event and i found the missing parts regarding creating a dummy click event here: http://stackoverflow.com/questions/4848892/list-tools-tab-is-no-longer-available-after-adding-webpart-to-the-page

The code looks like this:

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

function init_defaultWP(){
	setTimeout(function(){
		var defaultWP = document.getElementById("MSOZoneCell_WebPartWPQ1");
		WpClick({target:defaultWP,srcElement:defaultWP});
	},100);	
}

This code must be placed in the CEWP in the list view. Change the “WebPartWPQ1″ to whatever webpart you want to activate.

Add this code to a CEWP in the page.

You might also be interested in how to show the view selector that disappears as soon as you add another webpart to a list view

Alexander

Advertisement

3 Responses to “Bring back the missing list tools menu in list view with multiple webparts”

  1. PointsToShare Says:

    Excellent. I have blogged about the issue and was looking for a solution other than clicking on the desired web part. The simplicity of the solution is astounding! I will now add an entry that will direct the readers to this excellent post.

    Dov

  2. Christophe Says:

    Alexander, what is the purpose of the timeout?

    • Alexander Bautz Says:

      Hi Christophe,
      Without the timeout the ribbon was not ready to be “activated” when the script was called. There are surely other methods, but this was a simple fix.

      Alexander

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 )

Connecting to %s


Follow

Get every new post delivered to your Inbox.

Join 363 other followers