Tell me more ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a list view Grouped by Status column. Status Contains Active and closed values. now i want the default view to open with, Status:Active group to be Expanded and Status:Closed group to be collapsed.

share|improve this question

4 Answers

Are you familiar with jQuery? There is a click() function that does just that:

http://api.jquery.com/click/

So the idea would be to identify the first expand button and click on it. Something like this:

$("img[src*='plus.gif']").click();

Again, this seems like a heavy option, and just creating two views would be easier.

share|improve this answer

Although this post is quite old, this answer might help the ones who are searching for this functionality. In a list view grouped by Status column, where Active status should be expanded and Closes Status should be collapsed: Using IE developer tools or Mozilla Firebug, locate the (html element) image ID for the collapse-expand image (the '-' image). You'll find this img tag element to be enclosed within an tag. This tag has a javascript function for onclick event as shown below:

javascript:ExpCollGroup('1-1_','img_1-1_');return false;

Note that the image ID may differ based on your page. Also, Note that the expand collapse functionality is achieved by calling the javascript function 'ExpCollGroup'. All you have to do now is to script this function call in a CEWP added to your list view page (ignore the 'return false' part). Go ahead and add a content editor web part to your list view page and ensure that this CEWP is below the LVWP. Paste the following code in the source editor window of the CEWP:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" 
type="text/javascript"></script>
<script type="text/javascript">
$(function(){
    ExpCollGroup('1-2_','img_1-2_');
    // Include the function call for all the nodes that should be collapsed on page load
});
</script>

I had tried this solution on MOSS 2007 site, but I guess this solution may work for SP2010 also.

share|improve this answer

You don't have this option out of the box.

I would simply create two grouped views on the same page, one filtered for status active, and the other filtered for status closed.

Another solution would be to create the view as collapsed, and write a script that simulates a click after the view has loaded.

share|improve this answer

Using the ID will not work as is changing all the time, I'd use instead the name of the Category and in your case get find the related status and match category names. In my case I'm sending the name of the category in the URL to expand a category : (You can edit the page View or add a content editor web part)

function getParameterByName( name,href )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( href );
  if( results == null )
    return "";
  else
    return decodeURIComponent(results[1].replace(/\+/g, " "));
}
var category = getParameterByName( "category",document.URL);

$(".ms-commentexpand-iconouter").parent().parent().each(function(){
    if($(this).text().toLowerCase().indexOf(category.toLowerCase()) != -1)
        $(this).find("a").first().click();
});
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.