none
Expand first group but keep second group collapsed in List web part SharePoint Online RRS feed

  • Question

  • Hi

    I have a custom list with a couple of columns I am grouping by.

    Group by-
    System
    then group by
    Status

    I would like system to be expanded when the page loads but status not expanded (by default I have grouping as not expanded)

    I attempted to follow this and placed it in a CEWP under the list WP

    <script src="<link to JQuery.min>" 
    type="text/javascript"></script>
    <script type="text/javascript">
    $(function(){
        ExpCollGroup('1-2_','img_1-2_');
    });
    </script>

    The ID of the image which you can find with F12 an clicking on the expand/collapse 'column' -

    1-2_','img_1-2_

    is changing every time you refresh the page so it will only work once. So close - can anyone suggest anything?

    Thanks

    Jamie


    • Edited by Jamie_6 Monday, August 17, 2015 3:10 PM Add further detail
    Monday, August 17, 2015 3:08 PM

Answers

  • Hi,

    Here is a code demo which works in my environment, you can take it for a try in your environment:

    <script type="text/javascript" src="../../SiteAssets/js/jquery-1.11.1.min.js"></script>
    <script type="text/javascript">
    
    _spBodyOnLoadFunctionNames.push("ready");
    
    function ready()
    {
      setTimeout(ready1, 0);
    }
    
    function ready1()
    {
      var tid = "";
      var firstP = "";
      
      $(".ms-listviewtable tbody[id^=titl]").each(function(){
        tid = $(this).attr("id");
        if(3>tid.split('_').length)
        {
          if($(this).next().attr("style")!=="")
          {
            firstP = tid.slice(4);
            ExpCollGroup(firstP, "img_"+firstP);
          }
        }
      });
    }
    </script>
    

    Thanks

    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Thursday, August 27, 2015 5:23 AM
    Moderator

All replies

  • Hi,

    Here is a code demo which works in my environment, you can take it for a try in your environment:

    <script type="text/javascript" src="../../SiteAssets/js/jquery-1.11.1.min.js"></script>
    <script type="text/javascript">
    
    _spBodyOnLoadFunctionNames.push("ready");
    
    function ready()
    {
      setTimeout(ready1, 0);
    }
    
    function ready1()
    {
      var tid = "";
      var firstP = "";
      
      $(".ms-listviewtable tbody[id^=titl]").each(function(){
        tid = $(this).attr("id");
        if(3>tid.split('_').length)
        {
          if($(this).next().attr("style")!=="")
          {
            firstP = tid.slice(4);
            ExpCollGroup(firstP, "img_"+firstP);
          }
        }
      });
    }
    </script>
    

    Thanks

    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Thursday, August 27, 2015 5:23 AM
    Moderator
  • Hello - got this to work perfectly. Is there any way to set it up so that it only applies to one list/library on a page? We have a page with tabs that hold several different grouped lists, and I only want it applied to one of them.
    Monday, October 31, 2016 7:29 PM
  • Hi,

    I would say YES as this “ExpCollGroup()” function only work for a specific list view web part based on the parameters passed into it.

    The key to your requirement is, you need to “select” the specific list view web part with the help of jQuery/JavaScript selector, then pass the corresponding parameters to this “ExpCollGroup()” function should work.

    Best regards

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Tuesday, November 1, 2016 2:08 AM
    Moderator