4

Since the document library only displays 3 views and then you are forced to click on an ellipsis to see the other views is it possible OOB to somehow display all the views on a separate page ?

Most of my users fail to realize that additional views are available by clicking on the ellipsis. At minimum it would be cleaner if I could create a separate page and maybe thru a web part display all the views...

2

3 Answers 3

2

Get View names/links after display

On the View Page you could run a script after the page is displayed

var Views=eval(ctx.ListSchema.ViewSelectorPivotMenuOptions);//convert String to Array
SP.UI.Status.addStatus("This page has more Views hidden behind the <b>...</b>");
Views.forEach(function(View){//loop all Views
    console.info(View);
    var HTML=String.format("<a href='{0}'>{1}</a>",View.OnClickAction,View.DisplayText);
    SP.UI.Status.addStatus(HTML);
});

Change ViewSelector with CSR before display

If you use CSR (with a JSlink on the ListView webpart) you have full control over the ViewSelector before it is displayed:

Vadim posted it a couple of times:

  • How to display more than 3 views in document library?
  • SharePoint 2013 Library Views

    function renderHeaderTemplateWithAllViewsMenu(renderCtx, fRenderHeaderColumnNames){
        var viewData = eval(renderCtx.ListSchema.ViewSelectorPivotMenuOptions);
        ClientPivotControl.prototype.SurfacedPivotCount = viewData.length -2; //display all View options except 'Create View' & 'Modify View'   
        return RenderHeaderTemplate(renderCtx, fRenderHeaderColumnNames); //render default Header template
    }
    
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
      Templates: {
        Header: renderHeaderTemplateWithAllViewsMenu
      }
    });
    

Get View Names from another Page/List

I have never used it like this to construct the URL, so I think you have to construct the URLs from the Title yourself. (there is no URL defined in the ViewCreationInformation Object)

You can get the View definitions from (another) listID with:

var listID=SP.ListOperation.Selection.getSelectedList();
var context = SP.ClientContext.get_current();
var web = context.get_web();
var list=context.get_web().get_lists().getById(listID);
var views = list.get_views();
context.load(views);
context.executeQueryAsync(
    function(){
      var viewEnumerator = views.getEnumerator();
      while (viewEnumerator.moveNext()) {
        var view = viewEnumerator.get_current();
        var viewinfo={
          id:view.get_id()
          ,default:view.get_defaultView()
          ,title:view.get_title()
          ,jslink:view.get_jsLink()
          ,hidden:view.get_hidden()
          ,rowLimit:view.get_rowLimit()
          ,personalview:view.get_personalView()
          ,baseviewId:view.get_baseViewId()
          ,viewData:view.get_viewData()
          ,viewFields:view.get_viewFields()
          ,viewQury:view.get_viewQuery()
        }
        console.info(viewinfo);
      }          
    }, 
    function(){console.error(arguments);}
);

iView

2

Each view has a unique URL like /AllItems.aspx, /view1.aspx and so on, right? So if your views count is more than 3, but stable, what you can do is create a page with simple HTML content and manually put links to all views maybe adding some description. Wiki page will work even better

2
  • 1
    Thats what I initially started to do, but I wanted something more dynamic..If I get hit by a bus then the list will never get updated...but per your comment if I think the the views will be stable it is a possibility..why a Wiki page and not a reg. page
    – daPlayaURH
    Feb 20, 2016 at 5:09
  • 1
    Wiki is just easier to set up with all that '[[ |' syntax. Solutions up above are dynamic. I'd implement this one - sharepoint.stackexchange.com/questions/112543/… . Given modern monitors' width it seems logical to show all views in a row . PS. Please don't get hit by a bus :) Feb 20, 2016 at 9:26
2

Create an HTML Page and add the following Javascript. The following JS will fetch all the views on click of the button. You can modify it accordingly.

<script language="ecmascript" type="text/ecmascript">
       var web = null;
        var listCollection =null;
        var list = null;
        var viewCollection =null;

       function getViews() {
            var clientContext =new SP.ClientContext.get_current();
            if (clientContext != undefined && clientContext != null) {
                this.web = clientContext.get_web();
                this.listCollection = web.get_lists();
                this.list = listCollection.getByTitle("Documents");
                this.viewCollection = list.get_views();
                clientContext.load(this.viewCollection);
                clientContext.executeQueryAsync(Function.createDelegate(this,this.onQuerySucceeded), Function.createDelegate(this,this.onQueryFailed));
            }
        }

       function onQuerySucceeded() {
            var viewName ='Views: \n';
            var viewsEnumerator =this.viewCollection.getEnumerator();
            while (viewsEnumerator.moveNext()) {
                var view = viewsEnumerator.get_current();
                viewName += view.get_title() + '\n';
            }
            alert(viewName);
        }

       function onQueryFailed(sender, args) {
            alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
        }</script>
    <input id="btnGetViews" onclick="getViews()" type="button" value="Get All Views" />

Source: http://www.c-sharpcorner.com/UploadFile/anavijai/get-all-the-views-for-a-particular-list-in-sharepoint-2010-u/

2
  • So does this get views for the Documents library per your code above...
    – daPlayaURH
    Feb 20, 2016 at 5:13
  • Yes. It gets the views
    – Dhruv Jain
    Feb 20, 2016 at 9:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.