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

35 Comments on “Remove group label in grouped list view

  1. 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

    1. 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

    2. 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.

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

        Alexander

  2. 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

  3. 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

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

      Alexander

  4. Hello Alexander,

    Thanks for your solution, it works like a charm. I had a questiong how can I also hide the agreggations labels that are being added after chossing by example sum, average, etc.

    It now shows Sum=€1250, I want to remove the “Sum=” label.

    Thanks again.

    Jimmy

    1. I have the same question as Jimmy. Is it possible to remove the ‘Sum=” text from a ‘Total’ row in a list? The table cells simply contain text which is in bold and I can’t work out how to hide the ‘Sum= ‘ part of the text but leave the value that comes after it.

      Regards,

      David

  5. Here is the 2010 script if anyone wants to actually use it without having to manually remove the line numbers from copying/pasting.

    SharePoint 2010 script (jQuery reference omitted from above sample – Assumes jQuery is accessible):

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

    1. Hi,
      If you hover over the code view, you can select “view source” from the menu in the top right corner to get the code in plain text format (without the line numbers).

      Alexander

  6. Hi Alexander, Thanks for your solution, it really works great but i’m trying to combine this code with your code to Expand empty subgroups and remove group header in grouped list view. But this doesn’t seems to work, where am i going wrong? Can you please let me know.
    Thanks

  7. Hi Alexander. Thanks for this solution. It works great at removing the field labels. However, access to the Library Tools ribbons (Document and Library ribbons) are also disappearing. I don’t mind losing the List View selector, but those Library Tools ribbons are pretty important. Any idea what could be going on? Thanks in advance for your help!

  8. Just tried this using the 2010 code and it removed the field/column values and left in the field/column label and parenthetical number.

    For example,

    Car: Ford (5)
    Car: Toyota (3)

    became…

    Car: (5)
    Car: (3)

    Any idea what went wrong?

    Thanks!

  9. For Sharepoint 2013 I use:

    $(“table.ms-listviewtable td[class=’ms-gb’]”).each(function() {
    elem = $(this)[0];
    var linkNode = elem.childNodes[0];
    linkNode.removeChild(linkNode.childNodes[1]);
    var textNode = elem.childNodes[1];
    textNode.nodeValue = textNode.nodeValue.split(‘:’)[1];
    linkNode.appendChild(textNode);
    });

    Note that this is for the top level groups only.

  10. Hi,

    I added the below css codes to the page and it works for me.
    .ms-viewheadertr {display: none}
    .ms-gb {background-color:#00BDF2;color:#ffffff;border:#ffffff 1px solid !important;}
    .ms-gb a {color: #ffffff;}
    #WebPartWPQ7 table tr td table tr td.ms-vb2 {background-color:#9ae5fa;border:#ffffff 1px solid !important;white-space: normal;}
    #WebPartWPQ7 table tr td table tr td.ms-vb2 a {margin-left:5px;}

    WebPart 7 is the list I grouped on the page.

    1. Sorry, but I don’t have time to keep all solutions up to date. I suppose this should work more or less the same as in SP2010, but you might have to delay the function a bit for the view to finis rendering before applying the code.

      Alexander

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.