Compartilhar via


SP.View Class

Applies to: SharePoint Foundation 2010

Specifies a list view.

SP.View

Inherits

SP.ClientObject Class

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>

See Also

Reference

SP.View Methods

SP.View Properties

SP Namespace