Tuesday, May 4, 2010

HOW TO Display Expand/Collapse icons in a SharePoint List

Insert the following code in a Content Editor Web Part to display +/- icons to expand/collapse Items in a SharePoint List. The icons will appear in the Actions Menu in the List.

<script type="text/javascript" src="/../JavaScript%20Library/jquery-1.2.6.min.js"></script>

<script type="text/javascript">

function collapseGroups() {

$("img[src='/_layouts/images/minus.gif']:visible").parent().click();

}

function expandGroups() {

$("img[src='/_layouts/images/plus.gif']:visible").parent().click();

}

$(function() {

var expandAll = "<a href='#' onClick="

+'"'+"this.href='javascript:expandGroups()'"

+'"><img title="expand all groups" style="border:none;" alt="expand all" src="/_layouts/images/collapseplus.gif"></a>';

var collapseAll = "<a href='#' onClick="+'"'

+"this.href='javascript:collapseGroups()'"

+'"><img title="collapse all groups" style="border:none;" alt="collapse all" src="/_layouts/images/collapseminus.gif"></a>';

$("td.ms-toolbar[width='99%']").append(expandAll).append(collapseAll);

});

</script>

1 comment:

Clem said...

In SP2010, there is no actions menu on a list or doclib. It's necessary to add an href to the script to display links on the page for the user to click.