MOSS: The ViewStyle Tag
Side note: I thought I had blogged on this before, but I can't find any evidence that I did...
One of the more daunting tasks of SharePoint development is modifying the schema.xml files of a List definition; the CAML of the ViewHeader, ViewBody, ViewFooter, etc elements is tedious to wade through. Granted, if you need a custom view, you can simply copy and paste from an existing view, then modify as needed, but that adds over 1600 lines of XML to your Schema file. Not much fun.
Turns out there is a much simpler way: If you don’t have any need for custom rendering of the View, you can use one of the standard styles defined in the C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\GLOBAL\XML\VWSTYLES.XML file. These are the same views that are accessible from the SharePoint UI under View – Modify This View - Style group.
To apply one of these styles, use the ID attribute of the style from the VWSTYLES.XML file and add a <ViewStyle ID=”x” /> element to your View in the schema file. Then safely remove the ViewHeader, ViewFooter, ViewBody, ViewEmpty, GroupByHeader, GroupByFooter, PagedRowset, PagedClientCallbackRowset, and PagedRecurrenceRowset tags. That's a lot of XML saved.
Internally, the SPView.ApplyStyle() method is then called, and any View styles defined in the Schema file are overridden by the ViewStyle definition. (It is unknown how/if PagedClientCallbackRowset, PagedRecurrenceRowset, PagedRowset and other View child elements get their values set by the ViewStyle – that part of the code base is obfuscated.)
Labels: howto, moss, sharepoint
4 Comments:
Per http://msdn.microsoft.com/library/shared/deeptree/asp/rightframe.asp?dtcfg=/library/deeptreeconfig.xml&url=/library/en-us/odc_SP2003_ta/html/ODC_WSSAddingCustomViewStyle.asp the ViewStyle will default some values:
Keep the following points in mind as you create a custom view style:
* The ViewHeader, ViewBody, ViewFooter, and Script elements are required for every view style.
* Definitions for the GroupByHeader, GroupByFooter, and PagedRowset elements are drawn from the STDVIEW.XML file if they are not defined in VWSTYLES.XML.
* The PagedRecurrenceRowset element is only supported for view styles that can be applied to events lists.
By Oskar Austegard, at Thursday, April 03, 2008 3:55:00 PM
Also see my post MOSS: The dreaded schema.xml.
By Oskar Austegard, at Tuesday, April 28, 2009 3:25:00 PM
Five starts Oskar! Works like a charms so far. I'm using ViewStyles 0 and 17 (alternating list item bg).
By Michael Hanes, at Saturday, July 25, 2009 11:57:00 AM
Interesting post, for those willing to have default sharepoint view of the list they can use view style id=0
Cheers
By Mohamed Hachem, at Thursday, September 10, 2009 3:25:00 PM
Post a Comment
<< Home