Navigate Up
Sign In
Supporters of Developer
Web

SharePoint 2010 and the Mystery of the Disappearing View Selector Menu

Item is currently unrated. Press SHIFT+ENTER to rate this item.1 star selected. Press SHIFT+ENTER to submit. Press TAB to increase rating. Press SHIFT+ESCAPE to leave rating submit mode.2 stars selected. Press SHIFT+ENTER to submit. Press TAB to increase rating. Press SHIFT+TAB to decrease rating. Press SHIFT+ESCAPE to leave rating submit mode.3 stars selected. Press SHIFT+ENTER to submit. Press TAB to increase rating. Press SHIFT+TAB to decrease rating. Press SHIFT+ESCAPE to leave rating submit mode.4 stars selected. Press SHIFT+ENTER to submit. Press TAB to increase rating. Press SHIFT+TAB to decrease rating. Press SHIFT+ESCAPE to leave rating submit mode.5 stars selected. Press SHIFT+ENTER to submit. Press SHIFT+TAB to decrease rating. Press SHIFT+ESCAPE to leave rating submit mode.

 

Remember the good old days, before SharePoint 2010, when a dropdown on the top right of a List View Web Part (LVWP) allowed you to select different views, quicly and easily?

In SharePoint 2010 we have lost this handy feature. On some pages, a substitute does exist in the Breadcrumb on the title bar (which is part of the Ribbon, at the top of the page). It took us a little while to actually realize was there – but once we found it, it was very welcome.

2011-03-28-DisappearingViewSelectorMenu-01.png

But wait, all is not well. as Kerri from one of our partners – LookOut Software who develop CRM software for SharePoint – pointed out even the breadcrumb option disappears on the majority of pages. It disappears if you

  • Add another list view web part
  • Add any other web part such as a Content Editor Web Part containing things like instructions for the list
  • 3rd party web parts like our PivotPoint or FilterPoint tools that work really well alongside list views for creating dynamic dashboards.
  • use your list on a wiki page – and remember most of the pages in SharePoint 2010 are wiki pages by default now.

Also you don’t get it if you’ve created a new page and added a list view web part to it.

Once it’s gone, you have to resort to the following ninja moves to change a view. Select the list title (or something in the list) > List Tools > List, Current View dropdown > Then the view you want. 4 clicks? My finger is getting sore SharePoint!

2011-03-28-DisappearingViewSelectorMenu-02.png

This bugged me so much that I decided to look into it further and ended up developing a little tool which - well – rescues the view selector drop down.

If you just want the solution you can skip the rest of this post and download our free fix for this annoyance – ViewRescue

2011-03-28-DisappearingViewSelectorMenu-03.png

If you’re interested in the techie details then read on…

The class that generates this menu is ListTitleViewSelectorMenu.

Looking into this class with Reflector.NET you find the following snippet of code.

public override bool Visible { 
get {
if (!this.SingleWebPartPresentOnPage)
return false;
else
return base.Visible; 
} 
}

Basically, it’s set to not show the view selector if there is more than one web part on a page. I don’t know why this might be but I suspect that it’s because if there are more than 2 list view web parts on a page then which one do you choose to show the views for. Rather than complicate the UI with multiple choices or simply choose the first web part on the page I suspect the SharePoint development team decided to show nothing instead.

From there I found a post describing how you can use SharePoint Designer to modify a view’s .aspx page to put the view selector back. The problem with this method though is that you have to edit each view page individually and that also produces un-ghosted pages.

Instead I wanted something a little more automatic that you could apply to an entire site in one go.

Normally Delegate Controls are the way to achieve this sort of customisation, but the ListTitleViewSelectorMenu isn’t wrapped by delegate control so that’s out.

But what you can do is implement a delegate for the AdditionalPageHead delegate control that is included with every page in SharePoint.

In the OnLoad event of our delegate control we can find the ListTitleViewSelectorMenu and check if it’s visible. And if it isn’t (as there are more than one web part on the page) we can change it to be visible. Job done!

Except we can’t – the Visible and SignleWebPartOnPage properties are read only and everything else is hidden…

OK – we can create our own, derive from that class and override the visible property. Except we can’t – its sealed…

OK – lets use the nuclear option then! Use reflection to set the private properties in the class. This has obvious dangers should the class internals change – so this technique should only be done when there is no other choice.

Add some appropriate error handling code and were done for the standard lists, but what about Web Part or Wiki pages we’ve created and added a LVWP to?

In this case there is no ListTitleViewSelectorMenu on the page at all – visible or not. So what we have to do is to add our own – inside CreateChildControls we find the PlaceHolderPageTitlteInTitleArea control and add some spans and a ViewSelectorMenu (which is the class that the ListTitleViewSelectorMenu actually uses to render the menu).

This class needs to be told which List View Web Part (lvwp) to render the menu for so we find the first LVWP on the page and create an SPContext (which is a RenderContext) with the view to pass onto the ViewSelectorMenu.

Job done! Download our free ViewRescue tool today and banish this SharePoint 2010 annoyance from your life!

Categories: SPF 2010; SPS 2010; Solution Packages

Comments

Dave Pyett

Great timing!

Ha! the timing of this simply couldn't be any better for me as I was looking into this very issue last week. Thanks!

Posted 28-Mar-2011 by Dave Pyett
kurobar

excellent article

This excellent article assisted me very much! http://www.miniaturegolfer.co.uk/daydate-c-7

Posted 09-Sep-2013 by kurobar
Watchoh

Watches

Extremely details specifically the last part I care for such information and facts much. I was searching for this certain details for some time.

Posted 15-Sep-2013 by Watchoh
Logo Pearl

Re:

I like it all this is what I was roaming around my home thanks allot for this.

Posted 06-Nov-2013 by Logo Pearl
Buy Cheap Essay Uk

Re:

I thinks its really a good thing to understand it because we need it many times in our daily life.

Posted 10-Nov-2013 by Buy Cheap Essay Uk
Assignment Arena

Re:

you just got stuck on sharepoint 2010 what will you do when you switch to windows 7

Posted 09-Dec-2013 by Assignment Arena
fasd

fads

frre [url=http://www.roewele.org.uk/]dfgd[/url] http://www.rolrweele.org.uk/

Posted 18-Dec-2013 by fasd

Notify me of comments to this article

E-mail:
   

Add Comment

Title:

 
Comment:
Email:

   


Name:

 
Url: