View Element

The View element defines a view for a list in a Web site based on SharePoint Team Services from Microsoft, where each list can contain a number of views. Each view has an internal name that is typically represented by a GUID. The view can be rendered in a page by using the <View/> tag.

Syntax

<View
  BaseViewID = "Integer"
  DefaultView = "TRUE" | "FALSE"
  DisplayName = "Text"
  Editor = "SharePoint" | "FrontPage" | "Custom"
  FailIfEmpty = "TRUE" | "FALSE"
  FPModified = "TRUE" | "FALSE"
  FreeForm = "TRUE" | "FALSE"
  Hidden = "TRUE" | "FALSE"
  Name = "Text"
  PageType = "Text"
  ReadOnly = "TRUE" | "FALSE"
  RowLimit = "Integer"
  ShowHeaderUI = "TRUE" | "FALSE"
  Threaded = "TRUE" | "FALSE"
  Type = "HTML" | "Chart" | "Pivot"
  Url = "URL">
</View>

Attributes

Name Description
BaseViewID Optional Integer. Specifies the ID of the base view.
DefaultView Optional Boolean. Specifies whether this view is the default view.
DisplayName Required Text. Specifies the name of the view that is displayed on the Quick Launch bar.
Editor Optional. This field specifies the editing tool used to create the current view. In particular, it is used to signal that a view can be edited by a particular tool. Possible values include:
  • SharePoint Team Services The Web UI in the team Web site will assume it can only edit views whose format has been created by SharePoint Team Services.
  • FrontPageWhen Microsoft FrontPage edits a view incompatibly with SharePoint Team Services, it will change the Editor field to read "FrontPage."
  • CustomIn the case of custom view descriptions that cannot be edited in FrontPage or SharePoint Team Services, Custom indicates that the view is not editable by either tool.
FailIfEmpty Optional Boolean. If present and set to TRUE, and if this view contains no elements, instead of rendering the ViewEmpty element, the view returns a blank page and an HTTP error code. Used for programmatic manipulation of views from a client application, preventing the client application from having to parse a document to discover if the view is empty.
FPModified Optional Boolean. If present and set to TRUE, this view has been "poisoned" by editing in a Web page editor and is no longer customizable by the SharePoint Team Services Web UI.
FreeForm Optional Boolean. If present and set to TRUE, different field formatting for certain field types is triggered in field rendering. In particular, this affects the alignment of number columns and is particularly useful in custom non-tabular view types.
Hidden Optional Boolean. TRUE if the view is hidden.
Name Required Text. The name given to the view (used to select a different named view in the UI as well as to refer to a named view in specifying a filter for a Lookup field).
PageType Optional Text. When set to DialogView, this attribute allows customization, for use in client applications, of the built-in team Web views for the list of document libraries.
ReadOnly Optional Boolean. TRUE if the view cannot be modified.
RowLimit Optional Integer. Applies to the HTML view type only. Specifies the maximum number of rows to render on any one page. When the row limit is exceeded, the next and previous buttons on the page allow for viewing other parts of the returned recordset.

If RowLimit is not specified, the default number of Rows returned is 50. If "None" is specified for the view type, all the rows of the recordset are returned in one view.

When a view is rendered, the render variables ViewHasNext and ViewHasPrev are set to TRUE or FALSE based on whether the current view has reached the row limit from the dataset. These variables can be used in successive page definition to render Next and Previous buttons on the page, as in the following example:

<Switch>
  <Expr><GetVar Name=ViewHasPrev/></Expr>
  <Case Value=TRUE>
    <![CDATA[...Previous button defined here... ]]>
  </Case>
</Switch>

The variables NextPageURL and PrevPageURL are also set to non-blank values when there is forward or backward paging content from the current display. These variables can be used by constructing the Next and Previous buttons to have the correct URL for accessing the next page of content.

ShowHeaderUI Optional Boolean. If FALSE, all FieldRef elements used for the header display mode are rendered without the UI being decorated by HTML. In other words, when this mode is set, the UI does not provide sorting and filtering as click targets of the column header. The default value is TRUE.
Threaded Optional Boolean. If TRUE, this attribute acts as an inner grouping device. A threaded view is constructed based on the built-in threading column (assumed to exist for the list). The view is sorted on this field as the secondary sort. If other columns in the view are specified as sorted or grouped, those are applied before the threading column sort order. As a result, all discussions grouped by a topic can be collected together, and the message threading can be displayed beneath the collection.
Type Optional Text. Specifies the rendering type of the view. The type is the common enumerated HTML view. Can be set to HTML, Chart, or Pivot.
Url Optional URL. Specifies the URL for the view.
Parent Elements Child Elements
Default, Views, XML PagedRowset, Query, RowLimit, RowLimitExceeded, Toolbar, ViewBody, ViewEmpty, ViewFields, ViewFooter, ViewHeader

Remarks

The principle view type for list and document summary information is the HTML view. An HTML view is generally a columnar view that displays information from one or more lists. The data to be displayed is described by the fields that are shown in the view.

The primary attributes that define an HTML view are:

  • Its name.
  • Data source specification (usually a single list or document library).
  • Filter to be applied to the data source.
  • The collection of fields to be displayed.
  • The sort order of the items to be displayed. A special case of sort order is grouping.
  • An HTML template for rendering the view.

The View element is central to page rendering and generates an SQL query for the fields, sorts, and filters that are applied in a particular view. The View element iterates through the data set returned by the query and executes the ViewBody section for each row that is returned. Within the ViewBody section, a Fields element enumeration can be used to handle each field, or each field can be referred to individually by name within a Field element.

Example

The following example illustrates the use of a fields enumeration within a view body, laying out a basic table for displaying a list in the browser:

<ows:XML>
  <SetList>u_MyCustomList</SetList>
  <View Name="MyCustomView">
    <ViewHeader>
      <HTML><![CDATA[<TABLE><TR>]]></HTML>
      <Fields>
        <HTML><![CDATA[<TH>]]></HTML>
        <Field/>
        <HTML><![CDATA[</TH>]]></HTML>
      </Fields>
      <HTML><![CDATA[</TR>]]></HTML>
    </ViewHeader>

    <ViewBody>
      <HTML><![CDATA[<TR>]]></HTML>
        <Fields>
          <HTML><![CDATA[<TD>]]></HTML>
          <Field/>
          <HTML><![CDATA[</TD>]]></HTML>
        </Fields>
      <HTML><![CDATA[</TR>]]></HTML>
    </ViewBody>

    <ViewFooter>
      <HTML><![CDATA[</TABLE>]]></HTML>
    </ViewFooter>

Notice that the fields enumeration can also be used within a ViewHeader section to create column headers for the view.

A ViewFields section like the following is also included within the View element in order to specify which fields will be enumerated in a view:

    <ViewFields>
      <FieldRef Name="Created_x0020_By"/>
      <FieldRef Name="Last_x0020_Modified"/>
    </ViewFields>

Finally, the Query element is used to specify a result set that meets certain criteria, as in the following example, which returns a list of all the documents in a library that are written by Mary or John:

    <Query>
      <Where>
        <Or>
          <Eq>
            <FieldRef Name="Created_x0020_By"/>
            <Value Type="Text">
              Mary
            </Value>
          </Eq>
          <Eq>
            <FieldRef Name="Created_x0020_By"/>
            <Value Type="Text">
              John
            </Value>
          </Eq>
        </Or>
      </Where>
      <OrderBy>
        <FieldRef Name="Last_x0020_Modified"/>
      </OrderBy>
    </Query>
  </View>
<ows:XML>

The next view example displays a sequence of paragraphs. The Query element specifies not only a sort order (in order of modification date), but also a filter (only show items whose Expires property is greater than or equal to todays date).

<View Type="HTML" Name="Summary">
  <ViewBody ExpandXML="TRUE">
    <![CDATA[ <p><SPAN class=DocTitle><ows:Field Name="Title"/></SPAN>
      (<ows:Field Name="Author"/>, <ows:Field Name="Modified"/>)
      <ows:Limit><Field Name="Body"/></ows:Limit>
      </p>  ]]>
  </ViewBody>
  <Query>
    <Where>
      <Geq>
        <FieldRef Name="Expires"/>
        <Value Type="DateTime">
          <Today/>
        </Value>
      </Geq>
    </Where>
    <OrderBy>
      <FieldRef Name="Modified"/>
    </OrderBy>
  </Query>
  <ViewFields>
    <FieldRef Name="Summary"/>
    <FieldRef Name="Author"/>
    <FieldRef Name="Modified"/>
    <FieldRef Name="Body"/>
  </ViewFields>
</View>