Back to previous

Easy expand or collapse Sharepoint List in Group by view

When you group list items by some fields, by default Sharepoint have the items collapsed. It's quite annoying to have to manually expand each. There's a way you could easily expand all list items or collapse in one click.

Simply add a Content Editor web part and put the following JavaScript in source. Place it above your list view and done.

<script type="text/javascript">
if(typeof jQuery=='undefined'){
 var jQPath = 'http://ajax.googleapis.com/ajax/libs/jquery/1.3/'
 document.write('<script src="',jQPath,'jquery.min.js" type="text/javascript"><\/script>');
}
</script>
<script type="text/javascript">
/*
 * Copyright (c) 2008 Paul Grenier (endusersharepoint.com)
 * Licensed under the MIT (MIT-LICENSE.txt)
 */
function collapseGroups() {
 $("img[src*='minus.gif']:visible").parent().click();
}
function expandGroups() {
 $("img[src*='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>';
 $("table.ms-menutoolbar td.ms-toolbar[width='99%']").append(expandAll).append(collapseAll);
});
</script>

ShareThis

If you think this post is useful, please recommend me at the bottom of the page. ;)

Discussion