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
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
Alexander, what is the purpose of the timeout?
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
Fantastic !!! Your all client site scripts are really helpful.
All the scripts what every SharePoint Developer looking for !!
Thanks a Lot
Amazing solution.. I wasted 2 days to achieve this.. Your solution helped me like anything.. Thanks a TONNNNN….
Glad you liked it,
Alexander
Alexander (or anyone that has successfully gotten this to work) – I have pasted the code into a CEWP, changed the “MSOZoneCell_WebPartWPQ1” with my web part ID and it doesn’t change the ribbon hiding. I have also tried the two different snippets of code on the stackoverflow link above to no avail. I can provide more detail if it will help answer the question of what am I doing wrong. Thanks in advance for help with this! (Clicking somewhere in the list web part for the tool options to appear or closing/deleting the other web parts on the page are not options.)