SP.View object (sp.js)

Specifies a list view.

Applies to: apps for SharePoint | SharePoint Foundation 2013 | SharePoint Server 2013

var object = new SP.View()

Members

The View object has the following members.

Constructor

The View object has the following constructor.

Constructor

Description

View

Initializes a new instance of the SP.View object (sp.js).

Methods

The View object has the following methods.

Method

Description

deleteObject

Deletes the list view.

initPropertiesFromJson

renderAsHtml

Returns the list view as HTML.

update

Commits changed properties of the list view.

Properties

The View object has the following properties.

Property

Description

aggregations

Gets or sets a value that specifies fields and functions that define totals shown in a list view.

aggregationsStatus

Gets or sets a value that specifies whether totals are shown in the list view.

baseViewId

Gets a value that specifies the base view identifier of the list view.

contentTypeId

Gets or sets the identifier of the content type with which the view is associated so that the view is available only on folders of this content type.

defaultView

Gets or sets a value that specifies whether the list view is the default list view.

defaultViewForContentType

Gets or sets a value that specifies whether the list view is the default list view for the content type specified by contentTypeId.

editorModified

Gets or sets a value that specifies whether the list view was modified in an editor.

formats

Gets or sets a value that specifies the column and row formatting for the list view.

hidden

Gets or sets a value that specifies whether the list view is hidden.

htmlSchemaXml

Gets a value that specifies the XML document that represents the list view.

id

Gets a value that specifies the view identifier of the list view.

imageUrl

Gets a value that specifies the URI (Uniform Resource Identifier) of the image for the list view.

includeRootFolder

Gets or sets a value that specifies whether the current folder is displayed in the list view.

jsLink

Gets or sets the name of the JavaScript file used for the view.

listViewXml

Gets or sets a string that represents the view XML.

Note

The JSLink property is not supported on Survey or Events lists. A SharePoint calendar is an Events list.

method

Gets or sets a value that specifies the view method for the list view.

mobileDefaultView

Gets or sets a value that specifies whether the list view is the default mobile list view.

mobileView

Gets or sets a value that specifies whether the list view is a mobile list view.

moderationType

Gets a value that specifies the content approval type for the list view.

orderedView

Gets a value that specifies whether list items can be reordered in the list view.

paged

Gets or sets a value that specifies whether the list view is a paged view.

personalView

Gets a value that specifies whether the list view is a personal view.

readOnlyView

Gets a value that specifies whether the list view is read-only.

requiresClientIntegration

Gets a value that specifies whether the list view requires client integration rights.

rowLimit

Gets or sets a value that specifies the maximum number of list items to display in a visual page of the list view.

scope

Gets or sets a value that specifies the scope for the list view.

serverRelativeUrl

Gets a value that specifies the server-relative URL of the list view page.

styleId

Gets a value that specifies the identifier of the view style for the list view.

threaded

Gets a value that specifies whether the list view is a threaded view.

title

Gets or sets a value that specifies the display name of the list view.

toolbar

Gets or sets a value that specifies the toolbar for the list view.

toolbarTemplateName

Gets a value that specifies the name of the template for the toolbar that is used in the list view.

viewData

Gets or sets a value that specifies the view data for the list view.

viewFields

Gets a value that specifies the collection of fields in the list view.

viewJoins

Gets or sets a value that specifies the joins that are used in the list view.

viewProjectedFields

Gets or sets a value that specifies the projected fields that will be used by the list view.

viewQuery

Gets or sets a value that specifies the query that is used by the list view.

viewType

Gets a value that specifies the type of the list view.

Example

The following example creates an input button on an application page that orders the items on the Tasks list of the current site in descending alphabetic order.

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<script type="text/ecmascript" language="ecmascript">

    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("Tasks");
            var viewCollection = list.get_views();
            var view = viewCollection.getByTitle("All Tasks");

            var query = '<OrderBy><FieldRef Name=\'Title\' Ascending=\'False\' /></OrderBy>';

            view.set_viewQuery(query);
            view.update();

            clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
        }
    }

    function onQuerySucceeded() {
        alert('Tasks list ordered in descending alphabetic order.');
    }

    function onQueryFailed(sender, args) {
        alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    }

</script>

    <input id="Button1" type="button" value="Run Code" onclick="runCode()" />

</asp:Content>

REST resource endpoint

See View resource for more information.

Endpoint URI structure

http://<sitecollection>/<site>/_api/web/lists(listid)/Views(viewid)

HTTP requests

This resource supports the following HTTP commands:

DELETE syntax

DELETE http://<sitecollection>/<site>/_api/web/lists(listid)/Views(viewid)

MERGE syntax

MERGE http://<sitecollection>/<site>/_api/web/lists(listid)/Views(viewid)

POST syntax

POST http://<sitecollection>/<site>/_api/web/lists(listid)/Views(viewid)

PUT syntax

PUT http://<sitecollection>/<site>/_api/web/lists(listid)/Views(viewid)