Introduction In this article you will see how to get all the views for a particular list in SharePoint 2010 using ECMAScript. I have a list named "List Request" which has the following views (Navigate to the SharePoint list. Click on List tab in the ribbon interface. Click on List Settings button). In this you will see how to get all the views for a list "List Request" using ECMA script. Steps Involved
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("List Request"); 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" />
Reference SP.List.views Property - http://msdn.microsoft.com/en-us/library/ee557520.aspx Summary Thus in this article you have seen how to get all the views for a particular list in SharePoint 2010 using ECMAScript.
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: