SharePoint 2010 – The view selector is back!

In SharePoint 2010 you loose the list view selector in a list view if there are more than 1 web part in the page. This makes navigating the list views very cumbersome.

I have previously created a solution for adding a view selector in these list views, but that solution was a bit clunky.

I looked at this again today, and came up with a solution for re-enabling the missing list view selector that was clean and simple – and it doesn’t even require jQuery…

This is the first article where I’m using the “SharePoint 2010 Client Object Model”.

This solution is placed in a ContentEditorWebPart (CEWP) somewhere in the page you want the list view menu re-enable in. I recommend using the “Content Link” option in the CEWP as the code might be messed with by SharePoint if you paste it directly in the CEWP’s HTML-source.

To achieve this, put the code in a text-file and place it in a shares document library (all users must have read access), or in a folder created in SharePoint Designer. You then copy the file’s url and paste it into the “Content Link” field in the “Edit web part” panel like this:

You do not get any pictures of the menu itself as it is no different from the standard list view selector.

Here is the code:
Get the code here

25 thoughts on “SharePoint 2010 – The view selector is back!”

  1. Perfect timing for me too! Just face this issue today. Still need to try on my dev server. But one more issue is that ribbon for list view webpart won’t come up if we have more than one webparts on list view page. So, any idea what we can modify/add to script to make this working?

    Thanks in advance,

    1. Hi,
      Glad you liked it. I’m not entirely sure what you mean by the ribbon not coming up. With more than one list view web part in the page, you need to select one list by clicking on it to bring up the ribbon.


      1. Thanks for quick reply Alex.
        I tried your code it works like charm and got my view selector back. šŸ™‚
        The issue i am talking about, please check my blog for more details. Here i can’t upload images to give you proper explanation.
        Here is the link:

      1. Hi Alexander,

        Thanks for this solution. I am getting the same error as Tim (I think).. I’ve traced it to the line

        document.getElementById(‘ctl00_PlaceHolderPageTitleInTitleArea_ctl01_ctl00’).innerHTML += b.join(”); the buildMenu function. We have a customer master page with custom CSS. Our Content Place Holder ID is


        I changed all the document.getElementById references but the error remains? Any ideas?

        Many thanks!

    1. The link works. I am just used to seeing the code show up directly from the .txt file, and it’s blank for me now with an object expected error. I just did a “view source” though and saved it as a .js file. So, I’m good to go now. Thanks for sharing!

      Sorry for the extra question.


      1. No problem. This file is interpreted it as a web page and not as text, you should right click the file and select “save target as”.


  2. Many thanks Alexander – this works perfectly. I have spent a long time trying to find out how to get the view selector back. This is something that should be standard in SP 2010.

  3. This is awesome – I have literally spent several days searching for a solution and yours was a life-saver!! It works like a charm. As a note, I am using a second CEWP with the following HTML to show the ribbon on that page as well as the view:

    setTimeout(function() {
    var elem = document.getElementById(“MSOZoneCell_WebPartWPQ2”);
    if(elem != null) {
    var dummyevent = new Array();
    dummyevent[“target”] = elem;
    dummyevent[“srcElement”] = elem;
    }, 2000);

  4. Hi,

    Thanks for this code snippet!
    Do you have any idea how to support folders? Currently it’s always redirecting to the root folder. I tried to append the rootfolder to the ‘relUrl’ but that doesn’t seem to fix it for folders.

    function buildCustomViewMenuSucceeded() {

    //Get the rootfolder from the querystring + escape
    rtFolder = encodeURIComponent(getParameterByName(“RootFolder”));
    var viewInfo, currViewObj, viewEnumerator, view;
    viewInfo = [];
    currViewObj = {};
    viewEnumerator = this.customViewCollection.getEnumerator();
    while (viewEnumerator.moveNext()) {
    view = viewEnumerator.get_current();
    viewInfo.push({title:view.get_title(),guid:view.get_id(),relUrl:theRelViewUrlWithParams });
    for(var key in viewInfo){

    checkbool = matchingPathName == viewInfo[key].relUrl;
    currViewObj = viewInfo[key];



  5. Hi Alex- much thanks, it works great when used directly on list views. Do you have a solution for fixing the views where more than one list web part is added to a page? Appreciate any help. thanks,

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.