Thursday, May 2, 2013

Simple Concept: List View How to add context menu to the column?

[Question]: I want to add a context menu and a link  in the list view on the column that is NOT a default "Title" column. How can I do it?

You can either
1. implement xsltviewwebpart  (which is tedious task);

2. or you can using PowerShell set up special attributes to the field that you want to add a context menu and a link. 

I personally prefer the second approach. It allows a user to create a view over and over again and he\she will get the same behavior - a context menu and link to a specific , not a default title column.

Here is a simple magic:

 You have to add a following attributes to a desired <Field :


 Using PowerShell it will look like this:

$Lst = get-Splist "{full url}"
$prolFld = $Lst.Fields;
$Fld = $projFld.getField("{field static name}")                                                                                                                                                                                                                

#Save original Schema for backup purposes

$Fld.SchemaXml >> fldbkp.txt

#open fldbkp.txt. Copy the content over to the notepad.
#Add attributes LinkToItem="TRUE" LinkToItemAllowed="Required" ListItemMenu="TRUE". 
#Replace '"' with '''.Copy content

$Fld.SchemaXml ="{your copied edited field caml}"

P.S. It turned out that PowerShell SharePoint 2013 Snap-in
doesn't have a command sp-list!

So, here is an PS code for SP2013:

$web = Get-SPWeb{"{Url of spweb}"}
$list = $web.Lists['{List name}']
$Flds = $list.Fields;

$Fld = $Flds.getField("{Static Field name}")

3. For those who in SharePoint Online with limited PowerShell possibilities , you can add the context menu via SharePoint designer

Select the view, edit in Advanced mode.
Locate <ViewFields><FieldRef
Find you column that should have context menu.
And add the following:
So, it should like this:
<FieldRef Name="YourColumn" ListItemMenu="TRUE"/>

No comments:

Post a Comment