0

We have this code to do a "+" / "-" button to expand or collapse all groups.

<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>

We'd like all groups expanded by default with this jQuery code.

Please advise, as we've tried to change the View properties using "Expanded" for the groups, but the jQuery route is the display we're wanting. If we use Expanded for the grouping...and the group has 900 items, you have to go through all 900 items to get to the 2nd group. With the jQuery route, we don't.

1

If we use Expanded for the grouping...and the group has 900 items, you have to go through all 900 items to get to the 2nd group. With the jQuery route, we don't.

Not sure I understand how this works... if you use jQuery to expand a group that has 900 items on page load, then you would still have to go through 900 items to get to the second group, right? Or am I missing something?

In any case, in order to expand all groups by default, with the code you wrote, why not try this:

$(document).ready(function () {
    $(".ms-pivotControl-container").append(expandButton).append(collapseButton);
    // you already have the code to expand all...
    $("img.ms-commentexpand-icon").click();
});

or

$(document).ready(function () {
    $(".ms-pivotControl-container").append(expandButton).append(collapseButton);
    // for this one to work you need to make sure that the title of the 
    // collapse link actually says "collapse" instead of "expand"
    $("img[title*='expand']").click();
});

or

$(document).ready(function () {
    $(".ms-pivotControl-container").append(expandButton).append(collapseButton);
    // you already have the code to expand all...
    expandAll();
});
  • Was able to resolve via:<script> $(window).load(function () { $(".ms-commentexpand-icon").click(); }); </script> – Sol Web Solutions Jan 31 '18 at 16:56
1

Was able to resolve via:

<script>
 $(window).load(function () {
        $(".ms-commentexpand-icon").click();
   });
   </script>
  • Great! Please don't forget to mark your answer as accepted to close this question, also please check your previous questions and if any provided answers that you find it helpful for you, please upvote it and mark it as an answer to reduce the number of unanswered questions in communirty – Mohamed El-Qassas MVP Aug 7 '18 at 9:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.