View Element (List)
In a list definition (Schema.xml), defines a view for a list in a Web site based on Microsoft SharePoint Foundation, where each list can contain a number of views.
<View AggregateView = "TRUE" | "FALSE" BaseViewID = "Integer" ContentTypeID = "Text" CssStyleSheet = "Text" DefaultView = "TRUE" | "FALSE" DefaultViewForContentType = "TRUE" | "FALSE" DisplayName = "Text" FailIfEmpty = "TRUE" | "FALSE" FileDialog = "TRUE" | "FALSE" FPModified = "TRUE" | "FALSE" FreeForm = "TRUE" | "FALSE" Hidden = "TRUE" | "FALSE" ImageUrl = "Text" IncludeRootFolder = "TRUE" | "FALSE" List = "Integer" | "Text" MobileDefaultView = "TRUE" | "FALSE" MobileItemLimit = "Integer" MobileUrl = "Text" MobileView = "TRUE" | "FALSE" ModerationType = "Text" Name = "Text" OrderedView = "TRUE" | "FALSE" PageType = "Text" Path = "Text" ReadOnly = "TRUE" | "FALSE" RecurrenceRowset = "TRUE" | "FALSE" ReqAuth = "TRUE" | "FALSE" RequiresClientIntegration = "TRUE" | "FALSE" RowLimit = "Integer" Scope = "Text" SetupPath = "Text" ShowHeaderUI = "TRUE" | "FALSE" TabularView = "TRUE" | "FALSE" TargetId = "Text" TargetType = "List" | "ContentType" Threaded = "TRUE" | "FALSE" ToolbarTemplate = "Text" Type = "HTML" | "Chart" | "Pivot" Url = "Text" WebPartOrder = "Integer" WebPartZoneID = "Text"> </View>
Optional Boolean. TRUE to specify that the view is a Merge Forms view used in an XML Form library. By default, an XML Form library has a Merge Forms view that is initially hidden. When an XML editor is used to publish an XML Form Properties (XFP) file to the Forms directory of the library, along with a template used by the editor, the AggregateView attribute identifies the Merge Forms view. This view can be made visible or hidden, depending on whether the list template or definition for the library supports data merging.
Optional Integer. Specifies the ID of the base view.
Optional Text. Specifies the ID of the content type with which the view is associated.
Optional Boolean. TRUE to specify that the view is the default view.
Optional Boolean. TRUE to specify that the view is the default view for a content type.
Optional Text. Specifies the name of the view that is displayed on the Quick Launch bar.
Optional Boolean. If the view returns no items, TRUE to return a blank page and an HTTP error code instead of rendering the ViewEmpty element. Used for programmatic manipulation of views from a client application, so that the client application will not have to parse a document in order to discover whether the view is empty.
Optional Boolean. TRUE to specify that the view is displayed in file dialog boxes for applications that are used within the context of SharePoint Foundation, and that parse the output HTML to determine the contents of the list.
Optional Boolean. TRUE if the view has been altered through editing in a Web page editor, and the view is no longer customizable by the SharePoint Foundation user interface (UI).
Optional Boolean. TRUE to specify alternate field formatting for certain field types when fields are rendered. In particular, this attribute affects the alignment of number columns, which is particularly useful in custom nontabular view types.
Optional Boolean. TRUE to hide the view.
Optional Text. Specifies the server-relative URL for the image that is displayed in the title area of the list view, for example, /_layouts/images/pgrpicon.png.
Optional Boolean. TRUE to specify that the root folder is returned in the list view.
Optional Integer or Text. Specifies the type of list. This value can be either the ID of the template for a list (an integer), or the URL to a list provisioned in the site (a string). Best practice is to use Text, because Integer might not be specific enough (e.g., if there are two announcements lists in the site and you specify List=104).
Optional Boolean. TRUE to specify that the standard SharePoint list view is the default mobile view. Only one view per list can be designated as the default mobile view.
Optional Boolean. TRUE to specify that the standard SharePoint list view is also a mobile view. This attribute does not apply to Calendar, Datasheet, or Gantt views.
Optional Text. Specifies the Content Approval type, which can be HideUnapproved, Contributor, or Moderator. The HideUnapproved view hides unapproved draft items from users who only have permission to read items. The Contributor view shows the pending and rejected items for the current user. The Moderator view is accessible only to users who have managed list permissions and shows the pending and rejected items for all users.
Optional 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 when specifying a filter for a Lookup field.
Optional Boolean. TRUE to specify that the view is ordered.
Optional Text. Specifies the type of form in which the view is used. Possible values include the following:
Optional Text. Specifies the file name for the view.
Optional Boolean. TRUE to make the view read-only.
Optional Boolean. TRUE to expand recurring events in the view and display each instance of each recurring event. The default value is FALSE.
Optional Boolean. TRUE to use features that launch client applications; otherwise, users must work on documents locally and upload changes.
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 allow all of the returned recordset to be viewed.
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 definitions 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 nonblank 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 so that they have the correct URL to access the next page of content.
Optional Text. Specifies the recursive scope for a view of a document library. Possible values include the following:
Optional Text. Specifies the site-relative path to the folder in the setup directory that contains the .aspx page for the view, for example, pages\viewpage.aspx.
Optional Boolean. FALSE to render all FieldRef elements used in the header display mode without decorating the UI with HTML. In other words, when this mode is set, the UI does not provide sorting and filtering as hyperlinks in the column header. The default value is TRUE.
Optional Text. Possible values include List and ContentType.
Optional Boolean. TRUE to apply inner grouping in the view. 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 rules 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.
When TRUE, the RowLimit element has a different meaning when used on a threaded discussion board list view. Instead of specifying the number of items to return, it specifies the number of discussion threads to return, where a thread could consist of one or more items. In addition to having the Threaded attribute set to TRUE, a threaded view must be sorted by the thread ID; otherwise, this row limit behavior does not take effect.
Optional Text. Specifies the name of the predefined toolbar template that is used for the view toolbar.
Optional Text. Specifies the rendering type of the view. The type is the common enumerated HTML view and can be set to HTML, Chart, or Pivot.
Optional Text. Specifies the URL for the view.
Optional Integer. Specifies the vertical positioning of the Web Part within a zone.
Optional Text. Specifies the zone for the Web Part.
The principal 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. For information about how views work in Microsoft SharePoint Foundation 2010, see List Views.
The primary attributes that define an HTML view are as follows:
The data source specification (usually a single list or document library).
The 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 a 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 element for each row that is returned. Within the ViewBody element, 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.
Each view has an internal name that is typically represented by a GUID. The view can be rendered on a page by using the <View/> tag.
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.
<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 in the previous section the fields enumeration is used within a ViewHeader section to create column headers for the view.
In the following section of the example a ViewFields section is included within the View element in order to specify which fields will be enumerated in the view.
<ViewFields> <FieldRef Name="Created_x0020_By"/> <FieldRef Name="Last_x0020_Modified"/> </ViewFields>
In the last section of the example 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>
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 today’s 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>