Using JQuery to remove Linked List Items Hyperlinks – Revisited

So in an earlier post I talked about using JQuery to remove the A tag that is automatically included in the rendering of a linked list item in display mode.

I really liked this solution as it avoided having to go to the lengths of writing a custom field to solve this and can be targetted at a single page, or a whole site by embedding the code in the Master Page.

So, anyway, it’s worked quite nicely at the client that instigated the investigation, so I decided to re-use the code for a new client. This has functioned perfectly, right up to the point where they used a list view with a Group by in the selected view.

So, why does this cause different behaviour? Well the answer is in how the ListView web part handles the hiding and revealing of the grouped data. When you click on the expand link, the page performs a partial postback to SharePoint to get the missing data, before returning a block of HTML to display.

As this happens during the partial postback, the already registered code on the page doesn’t run a second time as the jQuery event $(document).ready doesn’t trigger again.

I tried various methods before placing a post on the StumpThePanel Q&A forum in the hope that “JQuery in SharePoint” god Paul Grenier would be able to answer my timing issues, which he did very nicely!

So how did we resolve it.. The answer is to replace the MicroSoft function that handles the posted back data within the listview ExpGroupRenderData() with a JQuery version.

function ExpGroupRenderData(htmlToRender, groupName, isLoaded) {

HideLinkedListItems() is the previously created function to strip the A tag frm linked list items, wrapped in a function wrapper so that it can be called frm either the update, or the Document.ready as per the original post.

The result, expanding the listview now presents the list view items, nicely stripped of their links.

I hope this helps someone achieve the same..


Leave a Reply

Your email address will not be published.


This site uses Akismet to reduce spam. Learn how your comment data is processed.