månadsarkiv: januari 2012

Add Edit Control Block (ECB) menu to custom column

Sometimes, as a developer, I tend to overthink things, not looking for the most simple of solutions for a problem. This was the case when I wanted to change the url of the linkTitle field on a custom list I made, to the url stored in a custom column in the same list. My first solution included jQuery and SharePoint javascript to get all the listItem objects for the items shown in a view, and for each of those, run queries to retrieve the data I needed. This solutions was poor because it consumed unnecessary resources and was not completely stable.

After being almost completely finished with the solution I thought that what I really wanted to achieve was adding the Edit Control Block (Short: ECB, see picture below) menu to my custom column, which really has the same effect (for me) as changing the url for the linkTitle column. A couple of searches and I found that this is done by simply adding a property to my custom column in my content type and list definition:

(Picture of ECB menu in swedish)

So instead of using like 40 lines of javascript code I could use a very small line of CAML. Very neat indeed. =)

So if you want to create a custom column with the ECB menu, you can define it like this (My example is for a hyperlink column):