Search code examples
sharepointcustom-fieldscustom-field-type

Sharepoint Custom Field Render Pattern: Render to multiple fields


Initial Question

Can I render the data from one field into multiple columns?

Background

I have created a custom field that contains a drop down list and two text boxes. The idea is that users can select a supplier from the drop down list that is connected to a list of suppliers. Which will get the contact name and number of the supplier and populate the corresponding textboxes.

I have done it this way as it is important to be able to override the contact number and the address but the client wants to see the defaults.

Heres what it looks like:

enter image description here

On saving the new entry the value of the field is saved as follows:

;#1;#Supplier 1;#Contact Name;#01234 567890;#

I chose to save the data in this was so I can treat it like a multi-column field when I render it.

I am using the below code to split the data and override the display pattern for the list view:

 <RenderPattern Name="DisplayPattern">
  <Switch>
    <Expr>
      <Column />
    </Expr>
    <Case Value="" />
    <Default>
      <!--<Column SubColumnNumber="0" HTMLEncode="TRUE" />
      <HTML><![CDATA[<br/>]]></HTML>-->
      <Column SubColumnNumber="1" HTMLEncode="TRUE" />
      <HTML><![CDATA[ - ]]></HTML>
      <Column SubColumnNumber="2" HTMLEncode="TRUE" />
      <HTML><![CDATA[ - ]]></HTML>
      <Column SubColumnNumber="3" HTMLEncode="TRUE" />
      <HTML><![CDATA[]]>]></HTML>
     </Default>
  </Switch>
</RenderPattern>

This allows me to present the data to the end user as follows:

enter image description here

Question

I would like to be able to display this split data in seperate columns. I notice that the build in title field SharePoint uses has four types of columns you can add to a view for a single field. I am trying to reproduce this kind of functionality so each section of the data can be added or removed from views. Is this possible?


Solution

  • It turns out you have access the list item which meant I was able to simply just add to additional fields within the list item by overriding the UpdateFieldValueInItem method.

     Public Overrides Sub UpdateFieldValueInItem()
        Me.ItemFieldValue = ddlSupplier.SelectedItem.Value
        If Me.Item.Fields.ContainsField(Me.Field.InternalName & "-" & "Telephone") Then
            Me.Item(Me.Field.InternalName & "-" & "Telephone") = txtTelephone.Text
        End If
    End Sub
    

    A much more effective way of doing this.