Problem with DisplayPattern in SharePoint 2010?

5.8k views Asked by At

I am adding a new field to a list using the AddFieldAsXML method of SPFieldCollection. The method executes fine with no problem. And the column header shows up when I view the list; however the value never displays in the column. Here is what the field looks like after it has been added to the list. This xml is a snipped from the list schema derived using http://tw-s1-m4400-007:4016/_vti_bin/owssvr.dll?Cmd=ExportList&List={1F87433F-50E1-46C5-A138-00E1CF7E5801}

This code works great in 2007 but does not work in 2010. Any help would be appreciated.

<Field ID="{e24ccb96-35fd-44e5-b7d1-4150dbbc9a64}" Type="Computed" ReadOnly="TRUE"
   Name="My_x0020_Status" DisplayName="MyStatus" ShowInEditForm="TRUE" ClassInfo="Icon"   
AuthoringInfo="(My status)" SourceID="http://schemas.microsoft.com/sharepoint/v3"       
StaticName="MyStatus" FromBaseType="TRUE">  
 <FieldRefs>
  <FieldRef Name="ID" /> 
  <FieldRef Name="Title" /> 
 </FieldRefs>
 <DisplayPattern>
 <HTML>
 <![CDATA[ <a href="form.htm?ID="
  ]]> 
  </HTML>
  <Column Name="ID" /> 
 <HTML>
 <![CDATA[ ">
  ]]> 
  </HTML>
  <Column Name="Title" /> 
 <HTML>
 <![CDATA[ </a>
  ]]> 
  </HTML>
  </DisplayPattern>
</Field>
4

There are 4 answers

0
user281254 On

This link provided a lot of help in solving this issue:

http://social.technet.microsoft.com/Forums/en/sharepoint2010customization/thread/ef0d1d22-47ff-416c-becd-13d48de80e4d

Basically, display patterns fields are defined in the C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\XSL\fldtypes.xsl file.

There is a file called fldtypes_ratings.xsl that you can use as an example of defining your custom field display.

You can create your own xsl file (i.e. fldtypes_myfile.xsl) to define your own custom display.

Here's a sample of my content:

<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" 
xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-
prefixes="xsl msxsl ddwrt" ns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" 
xmlns:asp="http://schemas.microsoft.com/ASPNET/20" 
xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal">

<xsl:template match="FieldRef[@Name='MyCustomField']" mode="Computed_body">
    <xsl:param name="thisNode" select="."/>
      <SPAN class="mystuff-content-item" style="Width:100%;text-align:center">
          <SPAN class='mystuff-socialized-status mystuff-socialized-status-unknown'></SPAN>
          <SPAN class="mystuff-content-object-type" style="display:none">
               MyContent
          </SPAN>
          <SPAN class="mystuff-content-followed" style="display:none">0</SPAN>
          <SPAN class="mystuff-content-name" style="display:none"></SPAN>
          <SPAN class="mystuff-content-id" style="display:none">
            <xsl:value-of select="$List" />
            <xsl:text>|</xsl:text>
            <xsl:value-of select="$thisNode/@ID" />
          </SPAN>
      </SPAN>
    </xsl:template>

</xsl:stylesheet>

Hope that helps!

0
Kirk Liemohn On

See my blog on this here: http://www.threewill.com/2012/07/computed-fields-in-sp-2010/. Hopefully this makes it clear on how to do computed fields in SP2010.

0
Tom Resing On

This method of customization from 2007 is made obselete by changes in 2010's rendering of fields. Read the note from the SDK entry on RenderPattern for more detail:

Important! This topic describes markup that was used in a now obsolete method of rendering custom fields types on list views and on the Display, Edit, and New forms. It is provided solely to assist persons who are debugging a custom field type that was originally developed against an earlier version of SharePoint Foundation. For information about the recommended methods, see How to: Create Field Rendering Templates and How to: Create a Custom Field Type. Custom fields whose rendering is defined with RenderPattern markup still render properly on forms. However, SharePoint Foundation, by default, uses XSLT stylesheets to render fields on list views, even for legacy custom fields whose list view rendering is defined with a RenderPattern. To enable the rendering of such a field, a TRUE element must be added to the containing FieldTypes element in the field type definition file (fldtype*.xml).

0
Eric On

I'm confused as to the point of referencing these articles -- both of them state "Two legacy field types that ship with SharePoint Foundation do not have a DisplayPattern type of RenderPattern in FLDTYPES.XML: (1) ContentTypeId fields are never visible. (2) Computed fields are rendered on list views and in Display mode by a DisplayPattern element in their Field elements within the schema.xml of each list on which they appear."

The original question is clearly defined as a "Computed" field, that according to the linked articles do not use the fldttypes.xml for their renderpattern, but intstead use the DisplayPattern element just as the original question posted. It would help to post references to how the DisplayPattern works in 2010 -- since the documentation clearly states that it Does work, but never says how.