4

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.

5 Answers 5

3

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.

1

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.

0

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.

0

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();
});
0

Use the dataform webpart to achieve above functionality.. Check on blog:- http://bborole.blogspot.co.uk/2013/08/expand-only-first-group-and-have-rest.html

2
  • Please do not provide link only answers, especially not to your own blog post. Commented Aug 25, 2013 at 13:38
  • Hi @Bhushan & welcome to our forum. When providing answers to posts please provide context when linking to another site. There are two reasons for this: first we like to keep all the knowledge in the forum itself, secondly external links tend to die, leaving others seeking the answer later on without a good answer. For guidance on providing good answers read "how to answer". Also: if you are going to link to your own blog, please provide full disclosure and avoid overt self promotion. Commented Aug 26, 2013 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.