Enabling ECB menu on a custom column in SharePoint 2010 (Part 2)

OK. In Part 1, I’ve explained the problem of “Edit in undefined” when you enable the ECB menu on a field in the document library. To workaround this problem, we have to go back to the way we used for MOSS. In MOSS, when we want to enable the ECB menu on a field, we have to define a custom field with the Computed field type and add references to two special fields, _EditMenuTableStart and _EditMenuTableEnd. We usually need to add another reference to a field from which the value of the custom field comes. So here in SharePoint 2010, let’s do the same thing.

The following is the definition of my custom field. I’ve highlighted the attributes and values which you may pay attention to. In this field, I want it to have the same value of Title so I add a reference to Title. Note in SharePoint 2010 now we use _EditMenuTableStart2 instead of _EditMenuTableStart. To make things simple, I also create a content type to use this custom field.

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <Field ID="{566F83FF-CCFE-4f7a-BE3C-332169E040B8}"
        Group="Morpheus Columns"
        AuthoringInfo="(with edit menu)"
            <FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" 
                      Name="Title" />
            <FieldRef ID="{1344423c-c7f9-4134-88e4-ad842e2d723c}" 
                      Name="_EditMenuTableStart2" />
            <FieldRef ID="{2ea78cef-1bf9-4019-960a-02c41636cb47}" 
                      Name="_EditMenuTableEnd" />
                    <GetVar Name="FreeForm"/>
                <Case Value="TRUE">
                    <Field Name="Title"/>
                    <Field Name="_EditMenuTableStart2"/>
                    <Field Name="Title"/>
                    <Field Name="_EditMenuTableEnd"/>
  <!-- Parent ContentType: Document (0x0101) -->
  <ContentType ID="0x010100922fc480f3ae4beba09c8eb3aec9530a"
               Group="Morpheus CTypes"
               Description="A content type with an ECB menu enabled field. "
        <FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" 
                  Name="Title" Required="TRUE" />
        <FieldRef ID="{566F83FF-CCFE-4f7a-BE3C-332169E040B8}" 
                  Name="TitleEx" Required="TRUE" />

Now if we deploy and use the content type in a document library, my field, TitleEx, is actually displayed as below. There is no value displayed, although there is a value in the Title field.


The reason why there is nothing in this field is the same as what I mentioned in my previous post: SharePoint 2010 now is using XSLT instead of <DisplayPattern> to render the field on the list view. Although I defined <DisplayPattern> for my field, it will never be used. We have to create a custom XSLT to render it.

The following is the XSLT stylesheet I used for my field.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema"
                exclude-result-prefixes="xsl msxsl ddwrt"

    <xsl:template match="FieldRef[@Name='TitleEx']" mode="Computed_body">
        <xsl:param name="thisNode" select="." />
        <xsl:param name="ShowAccessibleIcon" select="0"/>
        <a onfocus="OnLink(this)" href="{$FORM_DISPLAY}&amp;ID={$thisNode/@ID}" 
           onclick="GoToHistoryLink(this, {$thisNode/@_UIVersion});return false;" 
            <xsl:call-template name="LinkTitleValue">
                <xsl:with-param name="thisNode" select="$thisNode"/>
                <xsl:with-param name="ShowAccessibleIcon" select="$ShowAccessibleIcon"/>
        <xsl:if test="$thisNode/@Created_x0020_Date.ifnew='1'">
            <xsl:call-template name="NewGif">
                <xsl:with-param name="thisNode" select="$thisNode"/>

Now there is a value shown in my field, and it is the same as the value of Title.


The final step is to edit TitleEx in SharePoint Design and enable Show List Item Menu on it. After that, we will be able to see the ECB menu on this field. The result is below. It shows the “Edit in Microsoft Word” correctly.



Comments (12)

  1. trip says:

    Hi Chun! Thanx for your post. As I'm new in SP development, I'm not familiar where above XSLT code  must be putted? Somewhere in list definiton file(if yes, where precisely?) or somewhere else?

    Also does <DisplayPattern> must be defined because of use XSLT?

  2. Chun Liu says:

    The XSLT must be put in %ProgramFiles%Common FilesMicrosoft Sharedweb server extensions14TEMPLATELAYOUTSXSL. <DisplayPattern> is necessary if you want to show your field not only in list view but other forms like view properties form etc. XSLT just works for XSLTListViewWebPart. All other forms are still using the CAML defined by <DisplayPattern>. You can even force SharePoint to render your field with <DisplayPattern> only. Please refer to my previous post for details: blogs.msdn.com/…/rendering-a-field-with-the-custom-xslt-stylesheet.aspx.

  3. trip says:

    I did as you said (modification of my field definition with your field spec, added ref in CType,  added refs in list definition, added custom XSLT file,checked guids, reset of app pools) and NOTHING. I can't see any value in "TitleEx" in both cases (link to Title field or my custom field (which is final goal))

    As I develop this functionality just from code (with no assistance of SP Designer), can you maybe give me some hint on which I maybe forgotten?

  4. Chun Liu says:

    Try the solution I attached. Thx.

  5. SPLearner says:

    Hi Chun, thanks for your post.

    I'm new to SP, is it possible to create a field with the function of your  TitleEx field.I want this function can be used in everylist


  6. HenryW says:

    Good post, Chun.  Is there a way to change the XSLT to render the link so that it opens up the document, and not the item properties?

  7. GreatPost says:

    Hello Chun,

    I like your post but I have a small problem, it works perfectly but for some stupid reasons I got a javascript error when I load a view which renders this custom field

    I located the source of the problem, it comes from the GoToHistoryLink(this, {$thisNode/@_UIVersion});return false;

    any idea on the problem ?


  8. Exactly what I was looking for... says:


    Thank you for the post. I am having an issue thought. I think I am not getting the right steps.

    I created the XML file (I am using 'DocumentTitle' as my field name) and put it in the following folder with the following name:

    C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions14TEMPLATEXMLfldtypes_DocumentTitle.xml

    Then I created my XSL file and put it in the following folder with the following name

    C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions14TEMPLATELAYOUTSXSLfldtypes_DocumentTitle.xsl

    I restarted the IIS and I don't see where the new field should be. I am not sure what to do next, any thought?

    Any help would be greatly appreciated.

    • Pearl
  9. Sandeep Jha says:


    i added and deployed the solution. Then activated on my site. I can see the content type in my document library. But the two things are missing , the column "TitleEx"  is blank and then context menu.

  10. SandeepJha says:


    i added and deployed the solution. Then activated on my site. I can see the content type in my document library. But the two things are missing , the column "TitleEx"  is blank and then context menu.

  11. Changing link from show properties to open document. says:

    In the XSL, the link showing the Title will direct me to the page showing the properties (as the default behaviour for the title column in a list).

    <a onfocus="OnLink(this)" href="{$FORM_DISPLAY}&ID={$thisNode/@ID}"

              onclick="GoToHistoryLink(this, {$thisNode/@_UIVersion});return false;"


    <xsl:call-template name="LinkTitleValue">

                   <xsl:with-param name="thisNode" select="$thisNode"/>

                   <xsl:with-param name="ShowAccessibleIcon" select="$ShowAccessibleIcon"/>



    However for a document library, i would like the default behaviour of opening the document with the client application or in a web browser. I browsed through the entire field rendering xsl code on the server but didn´t an example which code i need for rendering an edit document link.

  12. Reggie says:

    Is there a way to do this using sandboxed solution since we can't deploy to _layouts?