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
Perfect timing! Just encountered it yesterday and was wondering if there’s a way to solve this
Does Monkeysoft do things like this just to purposely annoy users?
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,
Rajan
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.
Alexander
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: http://wp.me/pTOaG-3W
Hi,
Sorry, but I have no solution to this issue.
Alexander
For free: View Rescue for SharePoint 2010
http://www.pentalogic.net/sharepoint-products/free-sharepoint-web-parts/view-rescue
Hello, Looks like the link to the code is broken. Thanks
Hi,
The redirect from my old to my new server failed. I have updated the link.
Alexander
I get nothing but an error: “document.getElementById(…)’ is null or not an object”
Hi,
Have the master page been modified?
Alexander
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(”);
..in the buildMenu function. We have a customer master page with custom CSS. Our Content Place Holder ID is
ContentPlaceHolderId=”PlaceHolderPageTitleInTitleArea”
I changed all the document.getElementById references but the error remains? Any ideas?
Many thanks!
James
I cannot help with a custom master page. Use the developer tools in IE (F12) and inspect the placeholder to find the correct ID to use.
Alexander
Hi Alex,
I am unable to get to the code. Could you update once again please?
Thanks!
I’m not sure I follow you – does the link not work?
I have tested it and it does for me.
Alexander
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.
Alan
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”.
Alexander
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.
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;
WpClick(dummyevent);
}
}, 2000);
THANKS!!!!
You made my day!
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”));
alert(rtFolder);
var viewInfo, currViewObj, viewEnumerator, view;
viewInfo = [];
currViewObj = {};
viewEnumerator = this.customViewCollection.getEnumerator();
while (viewEnumerator.moveNext()) {
view = viewEnumerator.get_current();
theRelViewUrlWithParams=view.get_serverRelativeUrl()+’?RootFolder=’+rtFolder;
viewInfo.push({title:view.get_title(),guid:view.get_id(),relUrl:theRelViewUrlWithParams });
}
for(var key in viewInfo){
matchingPathName=unescape(location.pathname)+’?RootFolder=’+rtFolder;
checkbool = matchingPathName == viewInfo[key].relUrl;
if(checkbool){
currViewObj = viewInfo[key];
}
}
buildMenu(currViewObj);
}
Kr,
Francis
Hi Alex, many thanks for sharing. We were desperately looking such solution.
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,
Sorry, no.
Alexander