zaterdag 2 oktober 2010

SharePoint custom field type which shows an image

 

One of my present assignments is to make a custom field type. This field should be showing images in the listview webpart depending on the text value it holds. Now this should be easy to do right? Wrong… for some reason I could not get this to work.

What I want is a completely standard textfield that renders an image for certain texts. There are many blogs describing on how to do this. What I missed though is the fact that you must set <CAMLRendering> to TRUE if you want your HTML to show in the listview webpart.

This is described in MSDN: http://msdn.microsoft.com/en-us/library/aa544201.aspx. They state that:

Optional Boolean. The default is FALSE. Specifies whether the field is rendered on list views using the CAML markup in a RenderPattern element elsewhere within the parent FieldType element. The default FALSE means that the field is rendered on list views by an XSL transform in a fldtypes*.xsl file, which is the standard system for field rendering on list views. (However, this element has no effect on field rendering on Display, New, and Edit forms. A RenderPattern would still be the standard way of rendering the field on a Display form.)

My fieldref_.xml looked like this:

<?xml version="1.0" encoding="utf-8" ?>
<FieldTypes>
  <FieldType>
    <Field Name="TypeName">YourTypeName</Field>
    <Field Name="ParentType">Text</Field>
    <Field Name="TypeDisplayName">xxx</Field>
    <Field Name="TypeShortDescription">xxx.</Field>
    <Field Name="UserCreatable">TRUE</Field>
    <Field Name="Sortable">FALSE</Field>
    <Field Name="AllowBaseTypeRendering">TRUE</Field>
    <Field Name="Filterable">FALSE</Field>
    <Field Name="CAMLRendering">TRUE</Field>
    <Field Name="FieldTypeClass">Some.Namespace.AndClass, Some.Assembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=87iu1765432ade40</Field>
    <RenderPattern Name="DisplayPattern">
      <Switch>
        <Expr>
          <Column/>
        </Expr>
        <Case Value="Text1">
          <HTML><![CDATA[<img src="/_layouts/IMAGES/myImage.png" />]]></HTML>
        </Case>
        <Case Value="Text2">
          <HTML><![CDATA[<img src="/_layouts/IMAGES/OtherImage.png" />]]></HTML>
        </Case>
        <Default>
          <HTML><![CDATA[<span>No Value</span>]]></HTML>
        </Default>
      </Switch>
    </RenderPattern>
  </FieldType>
</FieldTypes

2 opmerkingen:

  1. Geen werving en selectiebureaus, enkel werkgevers! Solliciteer dus rechtstreeks bij de werkgever. Check jouw ict vacature!

    BeantwoordenVerwijderen
  2. Geen werving en selectiebureaus, enkel werkgevers! Solliciteer dus rechtstreeks bij de werkgever. Check jouw ict vacature!

    BeantwoordenVerwijderen