"List Tools" tab is no longer available after adding webpart to the page
Asked Answered
C

4

7

in SharePoint 2010 I have added my webpart above list (standard list or documents library list - it doesn't matter). After this "List Tools" tab is not visible. After some digging I have found, that problem exists even if I add one of the standard SharePoint WebParts.

Here is the same problem and description how to reproduce it: http://www.endusersharepoint.com/STP/viewtopic.php?f=10&t=2027

Has anybody found the solution or real workaround for this?

//EDIT: I've found a "solution". Ribbon is connected with "actual" webpart. One click on the list (to set the focus on it) and the tab is visible again :D

Capp answered 31/1, 2011 at 8:31 Comment(1)
What did you end up doing? I'm dying for a good solution!Honaker
C
4

Clicking on the list (setting focus on it) solved the "problem" ;)

Capp answered 31/1, 2011 at 9:2 Comment(1)
I think this should be the accepted answer (at least for Sharepoint online).Analogical
E
13

When you add a web part to the standard list views, the page is no longer classified as a list view page, but instead it is classed as an application page.

This means you lose the ribbon menu, as well as the view selector in the breadcrumb.

UPDATE

You can see the code that hides the view selector in:

Microsoft.SharePoint.WebControls.ListTitleViewSelectorMenu.SingleWebPartPresentOnPage

But I can't seem to find the code that hides the ribbon.

UPDATE

Okay i think this will work, add a content editor web part with this code:

<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);
</script>

Replace the MSOZoneCell_WebPartWPQ2 id with the web part zone cell of the list view web part.

Elderberry answered 31/1, 2011 at 8:47 Comment(3)
What does Update 2 mean when you say "this will work". Isn't this just clicking the webpart over and over again?Fungicide
No, he's using setTimeout instead of setInterval. setInterval would make that repeat itself. However, I tried that and it didn't work in my case.Bunsen
I tried this, and it sort of works (Sharepoint Server 2010). After the page loads, then the entire ribbon begins to show - you get the same thing if you use jquery to "click" on the list. What would be better if the ribbon tabs would show without the ribbon being automatically opened. - Ah! Check out @katrine's answer - that does just this!Honaker
E
8

This worked for me, but it starts with the documents tab selected, and I preferred to have the default browse tab selected to begin with, so I just added a simple line to the code, do reselect the default tab:

        <script>
        setTimeout(function() {
        var elem = document.getElementById("MSOZoneCell_WebPartWPQ2");
           if(elem != null) {
                var dummyevent = new Array();
                dummyevent["target"] = elem;
                dummyevent["srcElement"] = elem;
                WpClick(dummyevent);
                _ribbonStartInit("Ribbon.Browse", true)
            }
        }, 2000);
        </script> 
Enjoyable answered 5/7, 2013 at 9:19 Comment(3)
Ah! That seems to almost do the trick on my Sharepoint Server 2010. After the page loads, then I can see the ribbon tabs without the entire ribbon opening; however, if I click anywhere on the screen outside the ribbon or list, the ribbon tabs disappear again.Honaker
Why the timer, anyway? I tried it without the timer and it seemed to work just as well - well, that is with this instead: ` _spBodyOnLoadFunctionNames.push();`Honaker
I have the same issue. If I click outside of the list, it goes away.Smokejumper
F
5

After a ton of stepping through the SharePoint JS in a debugger, I've finally found a way to prevent this problem.

In SharePoint 2010:

//Set focus on our list web part
var webPart = document.getElementById('WebPartWPQ1');
WpClick({target: webPart});

//Prevent it from losing focus
SP.Ribbon.WebPartComponent.$3_1.deselectWebPartAndZone = function() { };

In SharePoint 2013 Beta:

//Set focus on our list web part
var webPart = document.getElementById('MSOZoneCell_WebPartWPQ2');
WpClick({target: webPart});

//Prevent it from losing focus
SP.Ribbon.WebPartComponent.$3.deselectWebPartAndZone = function() { };  

Note: This is super-hacky, and is in no way supported by Microsoft (thus it's very likely to change in a future version or possibly even the RTM of SharePoint 2013).

Also, note that your web part ids are likely to be different, so you should double check you're giving focus to the correct web part.

Explanation: It basically overrides the instance of SP.Ribbon.WebPartComponent's ability to deselect a web part. From what I can tell, the $3/$3_1 property stores a reference to the SP.Ribbon.WebPartComponent instance.

If anyone knows of a better way to access the instance of SP.Ribbon.WebPartComponent other than the $3/$3_1 property, please speak up, as that would be make this method much more robust.

Fungicide answered 24/9, 2012 at 16:39 Comment(0)
C
4

Clicking on the list (setting focus on it) solved the "problem" ;)

Capp answered 31/1, 2011 at 9:2 Comment(1)
I think this should be the accepted answer (at least for Sharepoint online).Analogical

© 2022 - 2024 — McMap. All rights reserved.