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.
Alexander
January 12, 2012 at 8:22 pm |
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
January 12, 2012 at 8:25 pm |
Alexander, what is the purpose of the timeout?
January 12, 2012 at 8:42 pm
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