Share via


How to rename column names in Content Query Webpart using property : DataColumnRenames

Requirement

  • How to rename column names in Content Query Webpart using property : DataColumnRenames

NOTE:

  • In any other Site except of Publishing Type, activate the following 2 features in your site, to have Content Query Webpart:
    1. In Site Collection Features: Office SharePoint Server Publishing Infrastructure
    2. In Site Features: Office SharePoint Server Publishing

Resolution

  1. Firstly, get the Internal Names for the columns (NOT Display Name) which will be shown in the Content Query Webpart. The easiest & accurate way is to create a console application and get the Internal Names

  2. The format for the values for the property DataColumnRenames in Content Query Webpart :
             OriginalName1,Newname1

    Multiple column renames are separated by semicolon. The below is valid one:
             OriginalName1,Newname1;OriginalName2,Newname2

    MOST IMP: Please DO NOT give any SPACES OR TAB while renaming multiple columns. Otherwise, only 1st column in row will be resolved.

    Note:

    • OriginalName means the Internal name (actual internal name in SharePoint & NOT that is changed N rendered by XSLT)
    • New Name can be any.
    • Query is made using the internal name (so in CommonViewFields property, we still required to specify Internal Names.)
    • Fields names are changed at the time of rendering by XSLT engine and not at time of querying.
  3. Example:

    • Suppose, we want the file/folder icons to be shown in the Content Query Webpart
      1. We will add the columns in the webpart xml by changing the property CommonViewFields:
                           <property name="CommonViewFields" type="string" >File_x0020_Type, Text;HTML_x0020_File_x0020_Type, Text</property>
      2. Now, we wanted to rename these fields, so that when we use in ItemStyle.xsl, its easier to read. Locate the word "DataColumnRenames" in the webpart
                        <property name="DataColumnRenames" type="string">File_x0020_Type,FileType;HTML_x0020_File_x0020_Type,HTMLFileType;</property>
      3. Now, in ItemStyle.xsl; the custom templates will extract value from Field Names : FileType, HTMLFileType