13

In SharePoint Lists, we can define new View and select the columns that we want to show.
I don't want to show the Title column but I also want to show the default Context Menu for the0 items on List.
How can I change the default "(linked to item with edit menu)" to another column instead of "Title" column?

13

i found the solution. it's really simple:

    SPList list = site.RootWeb.Lists["Tasks"];
    SPField field = list.Fields["Priority"];
    field.ListItemMenu = true;
    field.ListItemMenuAllowed = SPField.ListItemMenuState.Required;
    field.Update();
    list.Update();

and that's all.

  • 2
    Correction, approach with field.ListItemMenu = true; field.ListItemMenuAllowed = SPField.ListItemMenuState.Required; will work if you are using XSLT web part. MSDN – Natalia Tsymbalenko Aug 23 '12 at 21:46
6

You can add these options to Field xml - LinkToItem="TRUE" LinkToItemAllowed="Required" ListItemMenu="TRUE" to display Item Context Menu.

So it looks like:

    <Field Type="Text" ID="{87AC637E-BB54-48A4-BB7A-93973F6814A1}" StaticName="Country"
 LinkToItem="TRUE" LinkToItemAllowed="Required" ListItemMenu="TRUE" ClassInfo="Menu"
 AuthoringInfo="$Resources:core,Linked_Item_With_Menu;" Name="Country" 
DisplayName="$Resources:resource,Field_Country;" Required="TRUE"
></Field>
2

You're not going to be able to do this without deploying a new column through a feature.

Looking at how the current title with menu column is generated:

<Field ID="{<a new guid here>}" Name="LinkTitle" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="LinkTitle" Group="$Resources:core,Base_Columns;" ReadOnly="TRUE" Type="Computed" DisplayName="$Resources:core,Title;" DisplayNameSrcField="Title" ClassInfo="Menu" AuthoringInfo="$Resources:core,Linked_Item_With_Menu;">

    <FieldRefs>
        <FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" />
        <FieldRef ID="{bc91a437-52e7-49e1-8c4e-4698904b2b6d}" Name="LinkTitleNoMenu" />
        <FieldRef ID="{1344423c-c7f9-4134-88e4-ad842e2d723c}" Name="_EditMenuTableStart2" />
        <FieldRef ID="{2ea78cef-1bf9-4019-960a-02c41636cb47}" Name="_EditMenuTableEnd"/>
    </FieldRefs>

    <DisplayPattern>
        <FieldSwitch>
            <Expr>
                <GetVar Name="FreeForm" />
            </Expr>
            <Case Value="TRUE">
                <Field Name="LinkTitleNoMenu" />
            </Case>
            <Default>
                <Field Name="_EditMenuTableStart2" />
                <Field Name="LinkTitleNoMenu" />
                <Field Name="_EditMenuTableEnd" />
            </Default>
        </FieldSwitch>
    </DisplayPattern>
</Field>

Then it looks like you might get away with changing the references to LinkTitleNoMenu to the internal name of the field you want to show. However, you must make sure that the column you reference to is also a Site Column.

Do also ensure you change the static and display names of the column (replacing out 'LinkTitle' with something new of your choosing).

  • so im gonna create new feature with visual studio 2010 and add this tag with my custom field name into feature XML file and deploy the empty SharePoint template and it's done and if i wanna remove this column or field just retract the solution. am i right? – Jalali Shakib Jul 27 '11 at 5:09
  • Yes, though if you use the site column in a list or a content type, it won't be removed when you retract the solution. – James Love Jul 27 '11 at 7:15
  • first i wanna to know you did this before? because i test this and came up to one important note and it's: you can not define field with type "Computed", not with the object model(not gonna change) and not with sharepoint itself, if by any chance you do this, your field not gonna appear in sharepoint. i created a field and it's XMLSchema was just look like the "Title" field except the "Id", static and display names and it's type was anything except the "Computed". but the Context Menu doesn't appear. – Jalali Shakib Jul 27 '11 at 10:52
  • 1
    I haven't done this myself before, no, but that expert I pasted above was taken directly from SharePoint Manager, with just the GUIDs removed. From MSDN: "Computed Specifies a field that depends on another field for its contents. For example, a LinkTitleNoMenu field amounts to surrounding a Title field value with a hyperlink. Represented by the SPFieldComputed class." - msdn.microsoft.com/en-us/library/ms437580.aspx – James Love Jul 27 '11 at 11:00
  • i did create the field with all of you said but the field doesn't appear i think this is a hard solution, at least for me. thanks for your time. – Jalali Shakib Jul 27 '11 at 12:14
2

Try this code

SPList _list = _web.Lists["My List"];
SPField _field = _list.Fields["Name"];
_field.ListItemMenu = true;
_field.LinkToItemAllowed = SPField.ListItemMenuState.Required;
_field.ListItemMenuAllowed = SPField.ListItemMenuState.Required;
_field.Update();
_list.Update();
0

The Easiest way is to modify your view in SharePoint Designer :

Go to SPD 2013->Site->Your List->Your View .

Then add this two attributes to your FieldRef like this code :

<FieldRef Name="Title" ListItemMenu="TRUE" linkToItem="TRUE"/>

To be more explicit you find it in the View > ViewFields

<View Name="{D114F7F6-F87F-4A9F-BF24-D2A52B8BC6A7}" DefaultView="TRUE" MobileView="TRUE" MobileDefaultView="TRUE" Type="HTML" DisplayName="Tous les documents" Url="YourURl" Level="1" BaseViewID="1" ContentTypeID="0x" ImageUrl="/_layouts/15/images/dlicon.png?rev=23" ><Query><OrderBy><FieldRef Name="FileLeafRef"/></OrderBy></Query><ViewFields><FieldRef Name="Title" ListItemMenu="TRUE" linkToItem="TRUE"/></ViewFields><RowLimit Paged="TRUE">30</RowLimit><Aggregations Value="Off"/><JSLink>clienttemplates.js</JSLink><XslLink Default="TRUE">main.xsl</XslLink><Toolbar Type="Standard"/></View></XmlDefinition>
0

Yuri's answer:

LinkToItem="TRUE" LinkToItemAllowed="Required" ListItemMenu="TRUE"

worked fine for me. I went the the columns folder in VS 2015 and went to the element xml definition and added those properties to the column that I want the context menu to appear like this:

    <?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">  
  <Field
       ID="{48af9b3e-3c9d-42a2-a226-b20c2db16127}"
       Name="ProjectName"
       DisplayName="Project Name"
       Type="Text"
       Required="FALSE"
       LinkToItem="TRUE"
       LinkToItemAllowed="Required"
       ListItemMenu="TRUE"
       Group="Custom Site Columns">
  </Field>
</Elements>

After changing the attributes, I went to the Sites folder and opened the designer, removed the old column and added it again. I then went to the list schema to double check if the attributes are present in the node. In the View node, I then removed the LinkToMenu element. After committing all the changes, I ran the app and the context menu is now added to the column I desired.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.