Friday, February 13, 2015

Expand-Collapse All Groups in SharePoint 2013 List Views using jQuery

SharePoint doesn't has the ability to expand/collapse all groups in grouped list views. However, with jQuery we can bring Expand All-Collapse All buttons in SharePoint 2013 grouped list views. Just edit the grouped view page (Site Actions Gear >> Edit Page), add a "Script Editor" Web part and then place the below code in it.

jQuery for Expand-Collapse all items in grouped views in SharePoint 2013:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.2.6.min.js"></script>
 
<script type="text/javascript">
   
    function expandAll() {
        $("img.ms-commentexpand-icon").click();
    }
 
    function collapseAll() {
        $("img.ms-commentcollapse-icon").click();
    }
 
    var expandButton = "<a href='#' onClick="
 
    +'"' + "this.href='javascript:expandAll()'"
 
    + '">&nbsp;<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()'"
 
    + '">&nbsp;<img title="expand all groups" style="border:none;" alt="collapse all" src="/_layouts/images/collapseminus.gif"></a>';
 
    $(document).ready(function () {
        $(".ms-pivotControl-container").append(expandButton).append(collapseButton);
    });
</script>



and here is the result:
Thanks to: https://www.nothingbutsharepoint.com/sites/eusp/pages/jquery-for-everyone-expandcollapse-all-groups.aspx for the idea!

Read more: http://www.sharepointdiary.com/2014/07/expand-collapse-all-groups-in-sharepoint-2013-list-view-jquery.html#ixzz3Re7hfmvU

No comments:

Post a Comment