views:

1393

answers:

3

Is there a way to dynamically change the hyperlink associated with an ECB menu in WSS 3.0? For instance, I have a list with 2 fields. One field is hidden and is a link, the other is the title field which has the ECB menu. The title field currently links to the item's view page - but we want it to link to the link-field's url. Is that possible?


UPDATE - 5/29/09 9AM I have this so far. See this TechNet post.

<script type="text/javascript">
var url = 'GoTo.aspx?ListTitle='+ctx.ListTitle;
url += '&ListName='+ctx.listName;
url += '&ListTemplate='+ctx.listTemplate;
url += '&listBaseType='+ctx.listBaseType;
url += '&view='+ctx.view;
url += '&';

var a = document.getElementsByTagName('a');
for(i=0;i<=a.length -1;i++)
{
   a[i].href=a[i].href.replace('DispForm.aspx?',url);
}
</script>

This gives me a link like so (formatted so it's easier to see):

GoTo.aspx
?ListTitle=MyList
&ListName={082BB11C-1941-4906-AAE9-5F2EBFBF052B}
&ListTemplate=100
&listBaseType=0
&view={9ABE2B07-2B47-4390-9969-258F00E0812C}
&ID=1

My issue now is that the row in the grid gives each item the ID property above but if I change the view or do any filtering you can see that the ID is really just the row number. Can I get the actual item's GUID here?

If I can get the item's ID I can send it with the list ID to an application page that will get the right URL from field in the list and forward the user on to the right site.

A: 

I think the easiest solution and one I use regularly to modify default sharepoint functionality without having to install server side code is to inject some javascript onto the page to make the necessary modifications.

The Content Editor webpart is ideal for this if you don't want to edit the page source itself. Together with the IE Developer Toolbar or Firebug to inspect the elements you want to edit you should be able to achieve what you need with just a couple of lines of javascript.

Let me know if you need any further detail on getting this work.

I thought about that. But since the field with the URL is hidden, and not available in the DOM, I don't know how I can change the URL of the title field. Using the IE toolbar, I found the right spot in core.js and I know that I only have to change the href attribute of the title's anchor tag. I could do that in JavaScript, but getting the right URL may be difficult. Maybe I could render out a JavaScript array with the right URLs/title DOM ID and then replace the href on the fly...
dirq
A: 

The title/link to edit menu is a computed field - basically a combination of the title and item id. If you look at the definition of the field (off the top of my head I think it's in fields.xml) you should be able to create a modified version in your schema.xml that uses the url field in its RenderPattern.

Tom Clarkson
A: 

Following up on Tom's answer, you can use the SharePoint Solution Generator in VseWss 1.3 to generate a Visual Studio solution that can re-create your list. You will faint when you see the huge amount of XML that the views use in the schema.xml file but you will see the render pattern that Tom referred to and you should be able to get a general idea of how to modify it to suit your needs.

Gotta love SharePoint. Where small customizations means "take what I give you or rewrite it from scratch"

Josh Einstein