wtorek, 26 marca 2013

How to tune list view of style "Preview Pane". Part 1: duplicated "Name" field


When list's or library's view has style "Preview Pane", it shows all items' names in the list and the rest of the fields for the currently selected item is shown in the table. I don't like that the "Name" field gets duplicated in the list and in the table.

To correct this situation, run the SharePoint Designer and go to the view edition.
The inner name of the "Name" field is different for the list (LinkTitle) and for the library (LinkFilename). You can check the fields shown in the view looking for the <ViewFields> section in the code:

<ViewFields>
  <FieldRef Name="LinkFilename"/>
  <FieldRef Name="CustomField"/>
  <FieldRef Name="Modified"/>
</ViewFields>

First change the order of the fields so the "Name" field has the last position. You can do it in code or in Web GUI. 

Now find in code section that is responsible for drawing the table with fields:


<table class="ms-formtable" border="0" cellpadding="0" cellspacing="0" width="100%">
  <xsl:for-each select="ViewFields/FieldRef[not(@Explicit='TRUE')]">
    <tr>
      <td nowrap="nowrap" valign="top" width="190px"  class="ms-formlabel">
        <nobr>
          <xsl:value-of select="@DisplayName"/>
        </nobr>
      </td>
      <td valign="top" class="ms-formbody" width="400px" id="n{position()}{$WPQ}">
        <xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&amp;nbsp;</xsl:text>
      </td>
    </tr>
  </xsl:for-each>
</table>

Add the xsl:if statement to eliminate the Name field from the table:

<table class="ms-formtable" border="0" cellpadding="0" cellspacing="0" width="100%">
  <xsl:for-each select="ViewFields/FieldRef[not(@Explicit='TRUE')]">
    <xsl:if test="@Name!='LinkFilename'">
      <tr>
        <td nowrap="nowrap" valign="top" width="190px"  class="ms-formlabel">
          <nobr>
            <xsl:value-of select="@DisplayName"/>
          </nobr>
        </td>
        <td valign="top" class="ms-formbody" width="400px" id="n{position()}{$WPQ}">
          <xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&amp;nbsp;</xsl:text>
        </td>
      </tr>
    </xsl:if>
  </xsl:for-each>
</table>

Brak komentarzy:

Prześlij komentarz