You would like to use an out-of-the-box view of a list. But, the list’s column names are not the most end-user friendly. You’d like to modify the column names without losing any of the functionality of a list view web part, such as sorting and filtering. While you theoretically can use SharePoint Designer 2010’s design view to change the column header text, I’ve found it to be fairly unreliable. In other words, when I’ve tried it, I’ve had less than successful results. Fortunately, it’s easy to modify the XSLT to accomplish what we want to do.
The Set Up
In my example, I’m using the “My Tasks” view of a task list that’s associated with an approval workflow. I want my users to be able to quickly get to the the item they need to approve before being asked to approve or reject it. The column name for the associated item is “Related Content” – not exactly an intuitive title for most users. Since I know that in this site, the only thing stored in this task list is the tasks for the approval workflow, I can make this view more specific. We’re going to change “Related Content” to “Review Funding Request” and change “Title” to “Approve/Reject Request.”
To follow along you can use the out of the box approval workflow on any list, using the task list to track tasks.
Assuming you’ve set up your approval workflow, the first step is to get the “Related Content” column in our “My Task”s view. The “My Tasks” view is an out-of-the-box view on the task list. So, navigate to your tasks list, switch to the “My Tasks” view and choose “Modify this View.”
Add the “Related Content” column to the view. I made it the first column.
Save your view and open the site in SharePoint Designer 2010. Navigate to the Tasks list, and choose to edit the the “My Tasks” view. Switch to the Design tab and choose to “Customize XSLT” and select “Customize Entire View.”
Behold you will now have a couple thousand lines of XLST code in your code view. Don’t panic! Most of it can be ignored. You are going to do 2 things – add a custom template, and replace 18 instances of a specific line of code with a call to your custom template. (Find and Replace in SPD2010 is awesome.)
The Custom Template
Basically, instead of just outputting the field’s title, we want to output our custom text if the current field title matches the one we’re trying to replace. I’m replacing 2 field titles, so I’m passing in the current field title as a parameter, and then using a choose statement to do the comparison. If the current field title matches either of the 2 I’m replacing, I return my custom text. If not, I return the field title. Pretty simple. (Note that I begin the name of my custom XSLT templates with “CES” because that’s the organization I work for. You should have your own naming convention that ensures your template names will not conflict with Microsoft’s.)
<xsl:param name="fieldtitle" />
<xsl:when test="$fieldtitle = 'Title'" >
<xsl:value-of select="'Approve/Reject Request'" />
<xsl:when test="$fieldtitle = 'Related Content'">
<xsl:value-of select="'Review Funding Request'" />
<xsl:value-of select="$fieldtitle" />
I put my custom templates at the end of the existing XSLT code. To find the right spot, put your cursor in the code view in SPD2010 and search for
Insert the custom template just before this code.
(Note: don’t be shocked when you open the listview later and your code has moved. SPD2010 does that. No worries.)
Now, we need to call our template. You’re looking for the following code to replace:
<xsl:value-of select="$fieldtitle" />
And you’re going to replace it with this code:
<xsl:with-param name="fieldtitle" select ="$fieldtitle" />
(Note: Update the template name to match your custom template name. Also, make sure to highlight all of the XSLT EXCEPT your custom template when you do your find and replace selection. If you do the find and replace and include your custom template, you’ll get an infinite loop error.)
You should be able to run a find and replace procedure, and then click into the design view to have SPD2010 update the design view with your new column headers.
And, the finished view of the list, with all functionality intact.
This doesn’t work for attachment columns. But, it would be easy to handle those, as well. Attachments are output with disable-output-escaping=”yes.” You’d need to account for that in your custom template and then replace all the instances of:
<xsl:value-of select="$fieldtitle" disable-output-escaping="yes"/>
with your call to the custom template. I’m not changing that column name, so I didn’t include that.