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

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
August 17th, 2015 3:08pm

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
Free Windows Admin Tool Kit Click here and download it now
August 27th, 2015 1:25am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics