HTML Calculated Column: solutions for SP 2010 (Part II)

This series assumes that you are familiar with the “HTML Calculated Column” .

Part I: fallback to SP 2007
Part II: edit in SharePoint Designer

In this part II, I am going to show a straightforward method that can be applied via SharePoint Designer.

In SharePoint 2010, lists are rendered through a new component, the XSLT List View (XLV) .

Let’s add to a page a list with an HTML Calculated Column. Naturally, this column will be rendered as text. If we edit the page in SharePoint Designer, in split mode, it will look like this (click picture to enlarge):

The XSLT hierarchy is displayed at the bottom of the page. The tag that renders the field reads as follows:

<xsl:value-of  select="$thisNode/@*[name()=current()/@Name]">

This is a complicated expression, but for our purpose we don’t need to understand it. What we are going to do is tell SharePoint to interpret the field as HTML instead of just text, by adding the disable-output-escaping attribute (see picture below):

<xsl:value-of select="$thisNode/@*[name()=current()/@Name]" disable-output-escaping="yes">

 And here we go, the field is now rendered as HTML:

 The final result in the browser:

Note that the HTML rendering is done in the XSLT view itself. So if you have asynchronous updates enabled, all content refreshes will be rendered as HTML.

How about SP 2007?

We’ve actually already used this method before, in cross-list views:
– with Content Query Web Parts, as demonstrated by Eric Proshuto
– with Data View Web Parts, in my KPI roll-up series

Dealing with a standard Data View Web Part is more difficult, as explained here.

Conclusion: the HTML Calculated Column plays better with the XSLT List View in SP 2010 than it did with the Data View Web Part in SP 2007.

Your feedback and suggestions are welcome, they will guide me in my investigations. Also, let me know if you need more details on the step shown in this post.

Advertisements

13 thoughts on “HTML Calculated Column: solutions for SP 2010 (Part II)

  1. Hi Christophe,
    That’s seems simple enough!
    Could you document the explanation for the existing and added portion of
    ?

    Always curious!
    Greg

  2. Pingback: Links (6/15/2010) « Steve Pietrek-Everything SharePoint/Silverlight

  3. Pingback: HTML Calculated Column: solutions for SP 2010 (Part III) « Path to SharePoint

  4. Pingback: HTML Calculated Column: solutions for SP 2010 (Part IV) « Path to SharePoint

  5. Hello Christophe,
    The changeover worked as advertised, as always, but I have an observation/question. If you customize the view with sorting or filtering the <DIV tags continue to be processed correctly, but if the view is grouped with the collapsed option set, the <DIV tags are not processed correctly when expanded. However if the view is Grouped with the expanded option selected the calculated columns are displayed correctly even if you then collapse them and expand them again.

    Is there a way around this?

    Thanks,

    Wade…………….

    • Was Wade’s question ever resolved? I am having the same problem – when a view has collapsed groups, the DIV tag code does not render as HTML when a group is expanded. Curiously, when you expand an adjacent group, HTML suddenly renders for the previous group – but never for the group you just expanded.

      I also tried Patrick EMIN’s suggestion, below (Sept 11, 2010). However as soon as I apply “Enable Asynchronous Update”, all groups display as Expanded (the Collapsed setting is ignored).

  6. Pingback: External list example demonstrating .NET connectivity assembly and custom field type « Second Life of a Hungarian SharePoint Geek

  7. Hi, you have to check “Activer la mise à jour asynchrone” for this to work in SP2010 (activate asynchronous update?). Don”t activate any other Ajax option, works like a charm…

    • Unfortunately, choosing “Enable Asynchronous Update” makes the groups show as Expanded, initially, even though the view is defined to initially show all groups as Collapsed. I’d like the view to begin with Collapsed groups, and still have the calculated column HTML render correctly when the first group is manually expanded…

  8. Pingback: HTML Calculated Column: solutions for SP 2010 (Part IV) « maiomardesouki

  9. Pingback: SP « ShowMeTheData

Comments are closed.