Is there a way to add a button to a SharePoint 2010 page to expand all grouped items in all the list views on the page? This is the first (top) level grouping only, not the second level. These are simple (standard) list views created via the web UI, where we've grouped items on one or two columns. Thanks.
3 Answers
Yes this is possible. You can use some javascript to do that. Here is a post about this. http://alectang.com/blog/archive/2010/09/09/easy-expand-or-collapse-sharepoint-list-in-group-by-view.aspx
The trick is to find the little minus button and then click it:
function expandGroups() {
$("img[src*='plus.gif']:visible").parent().click();
}
-
1Thanks, SPSinan. What if I have two levels of grouping and need all to be expanded?– Alex CCommented Dec 14, 2011 at 15:06
-
Found the answer: Just remove the
:visible
from the statement and it works on the hidden grouped elements too :)– Alex CCommented Dec 15, 2011 at 4:41 -
Tried this in SP 2010. Could not get it to work. Thanks anyway.– ClemCommented Jan 4, 2012 at 13:13
-
-
This doesn't seem to work with SP2010. Any ideas with SP 2010 Thanks Commented Dec 17, 2012 at 4:47
one way for making sure all 3 levels are expanded
<script src="https://portal/SiteAssets/jsLibrary/jquery.1.9.1.min.js" type="text/javascript"></script>
$(document).ready(function () {
// Wait until SP.JS has loaded before calling expandAll
ExecuteOrDelayUntilScriptLoaded(expandAll, "sp.js");
});
function expandAll(){
//for making sure all 3 levels are expanded
$("img[src$='plus.gif']").parent().trigger("click");
$("img[src$='plus.gif']").parent().trigger("click");
$("img[src$='plus.gif']").parent().trigger("click");
}
This works too.
<script type="text/javascript">
function expandAll() {
$('img[alt="expand"]').click();
}
function collapseAll() {
$('img[alt="collapse"]').click();
}
var expandButton = "<a href='#' onClick="
+'"' + "this.href='javascript:expandAll()'"
+ '"> <img title="expand all groups" style="border:none;" alt="expand all" src="/_layouts/images/collapseplus.gif"></a>';
var collapseButton = "<a href='#' onClick="
+'"' + "this.href='javascript:collapseAll()'"
+ '"> <img title="expand all groups" style="border:none;" alt="collapse all" src="/_layouts/images/collapseminus.gif"></a>';
$(document).ready(function () {
$(".div").append(expandButton).append(collapseButton); // select div where you would like to place the icons.
});
</script>