We have added a list view web part to a page, and we get the Current View
link in the web part. Which is configurable when modifying the actual web part.
What we'd like to see (instead of having to click the ellipses button/context menu to get the other views) is the views displayed horizontally like when you are viewing the list itself.
When viewing the list itself, we see All Items
View 1
View 2
, etc.
Is this possible in the list view web part to display all available views in a horizontal/breadcrumb layout? Please advise.
Trying this in simple webpart code snippet to get back all views:
<script>
var viewCollection = null;
function runCode() {
var clientContext = new SP.ClientContext.get_current();
if (clientContext != undefined && clientContext != null) {
var web = clientContext.get_web();
var listCollection = web.get_lists();
var list = listCollection.getByTitle("MyListName");
this.viewCollection = list.get_views();
//var viewInfo = new SP.ViewCreationInformation();
//viewInfo.set_title('MyView');
//this.viewCollection.add(viewInfo);
clientContext.load(this.viewCollection);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
}
function onQuerySucceeded() {
var viewInfo = 'Tasks list current views: \n\n';
var viewEnumerator = this.viewCollection.getEnumerator();
while (viewEnumerator.moveNext()) {
var view = viewEnumerator.get_current();
viewInfo += view.get_title() + '\n';
}
alert(viewInfo);
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
</script>
<a onclick='return runCode();'>Click here</a>
Content Editor
web-part on top of the list view web-part. Then format it as per your wish.View
URL's.