Remove group label in grouped list view


17.09.2011 I have updated the script to support lookup columns and people pickers.


I got a request from Djamel asking for a solution for removing the group label (the field name) in a grouped list view.

Add this code to a Content Editor Web Part (CEWP) in the list view. Adding a CEWP in a SharePoint 2010 list view will unfortunately remove the list view selector.

SharePoint 2007

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){	
	$("table.ms-listviewtable td[class^='ms-gb']").each(function(){
		var aLen = $(this).find('a').length;
		switch(aLen){
			case 2:
				var newLabel = $(this).find("a:last")[0].nextSibling.nodeValue;
				$(this).find("a:last")[0].nextSibling.nodeValue = '';
				$(this).find("a:last").text(" "+newLabel.substring(3));
			break;
			case 3:
				var newLabel = $(this).find("a:last").text();				
				$(this).find("a:eq(1)")[0].nextSibling.nodeValue = '';
				$(this).find("a:eq(1)").text(newLabel+" ");
				$(this).find("a:eq(2)").remove();
			break;			
			case 4:
				var newLabel = $(this).find("a:eq(2)").text();
				$(this).find("a:eq(1)")[0].nextSibling.nodeValue = '';
				$(this).find("a:eq(1)").text(newLabel+" ");
				$(this).find("nobr:last").remove();
			break;
		}
	});	
});
</script>

SharePoint 2010

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	$("table.ms-listviewtable td[class^='ms-gb']").each(function(){
		var newLabel;
		var aLen = $(this).find('a').length;
			switch(aLen){
			case 1:
				newLabel = $(this).find("a:last")[0].nextSibling.nodeValue;
				$(this).find("a:last")[0].nextSibling.nodeValue = '';
				$(this).find("img:last")[0].nextSibling.nodeValue = " "+newLabel.substring(3);
			break;
			case 2:
				newLabel = $(this).find("a:last")[0].nextSibling.nodeValue;
				if(newLabel === null){		
					newLabel = $(this).find("a:last").text();				
					$(this).find("a:last").remove();
					$(this).find("a:first")[0].nextSibling.nodeValue = '';
					$(this).find("img:first")[0].nextSibling.nodeValue = " "+newLabel;
				}else{
					$(this).find("a:last")[0].nextSibling.nodeValue = '';
					$(this).find("a:last").text(" "+newLabel.substring(3));
				}
			break;
			case 3:
				newLabel = $(this).find("nobr:last").text();
				$(this).find("nobr:last").remove();
				$(this).find("a:eq(0)")[0].nextSibling.nodeValue = '';
				$(this).find("img:last")[0].nextSibling.nodeValue = " "+newLabel;
			break;			
		}
	});	
});
</script>

Ask if anything is unclear.

Alexander

18 Responses to “Remove group label in grouped list view”

  1. lyverbak Says:

    Hi Alexander,

    YOU ARE THE BOSS :) )

    Just tested and it works like a charm :) ))

    Thanks for your help !!

    Best personal regards

    Djamel

  2. guigoss Says:

    Hi Chris,

    Thanks for your great job!
    it works well in a document library page: (http://mysite/subsite/doclibname/Forms/AllItems.aspx).
    But it doesn’t seem to work in a webpart page where you can add document library as a webpart.

    an you please help.

    Thanks a lot.

    Regards.

  3. Robert Says:

    Hi Alexander,

    I have used this script on SP2007 and it worked like a charm, and I’m glad you posted the script for SP2010 also.
    I have tried and it works as good as the old script!

    Now I wonder if there is a way to not only remove the group heading but also part of the text?

    I am thinking about a list that looks like this:

    +Headline: aaaaaa (1)
    +Sub-headline: bbbbbb (1)
    Document 1

    +Headline: cccccc (1)
    +Sub-headline: N/A (1) ‘This line should be removed’
    Document 2
    ———–
    I want the list to remove all sub-headlines that have the category “N/A” so it looks like this:

    +Headline: aaaaaa (1)
    +Sub-headline: bbbbbb (1)
    Document 1

    +Headline: cccccc (1)
    Document 2
    ———–

    Is it possible to “target” a specific text for removal in a list like this?

    Regards // Robert

    • Robert Says:

      Sorry, in the “After”-list it’s supposed to look like this:

      +aaaaaa (1)
      +bbbbbb (1)
      Document 1

      +cccccc (1)
      Document 2

    • Alexander Bautz Says:

      Hi,
      If you want to remove the entire category if it’s label i “N/A” – couldn’t you just filter the list view to remove them?

      Alexander

    • Robert Says:

      I still want the document in the N/A category to be visible in the list but want the N/A category to be hidden, so if I filter out N/A from the list then I will also hide the documents under this category.

    • Alexander Bautz Says:

      Have you looked at this one?

      You can modify the script by changing line 32 from

      if(grName.length==0){
      

      to

      if(grName==="N/A"){
      

      Alexander

    • Robert Says:

      Sorry, I can’t get the solution above to work in SP2010.
      //Robert

    • Alexander Bautz Says:

      Hi, Sorry, but i have not ported all solutions to SP2010. I will try to find time, but i cannot promise anything.

      Alexander

  4. jbooker Says:

    Alexander,

    Great Site. Noticed you mentioned the dreaded missing View Selector. Have you looked at reactivating that using js? I understand this is by design to handle case when view selection may not be applicable to selected wp, but removeing it even when a list view is selected sounds lazy on the part of MS.

    Josh

  5. Dave Says:

    Is there a way to remove the group totals? E.g. “Matrices (2)” to just “Matrices”

    • Alexander Bautz Says:

      Like this:

      $("td[class^='ms-gb']").each(function(){
      	$(this).find("span:last").remove();
      });
      

      Alexander

  6. SV Says:

    Seems to have a problem with IE 7. Rest of browser things work fine.

  7. Walter Says:

    So, this should suppress the group totals?

    $(“td[class^='ms-gb']“).each(function(){
    $(this).find(“span:last”).remove();
    });

  8. Walter Says:

    With a document library, it is successfully supressing the first “set” of group headers, but subsequent group headers are still be displayed; i.e.

    Group1 (suppressed)
    Group2 (Suppressed)

    Group1: Displayed
    Group2: Displayed
    Group2: Displayed

    Group1: Displayed
    Group2: Displayed

    Thought maybe the toolbar setting might be an issue but didn’t see a change in behavior

    • Alexander Bautz Says:

      Is this SP2007 or SP2010?
      Activate the “Console” in your browser by hitting F12 and look for errors – post your findings here.

      Alexander

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.

Join 435 other followers