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
Hi Alexander,
YOU ARE THE BOSS :))
Just tested and it works like a charm :)))
Thanks for your help !!
Best personal regards
Djamel
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.
Hi,
Remember to put the CEWP below the list view web part.
Alexander
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
Sorry, in the “After”-list it’s supposed to look like this:
+aaaaaa (1)
+bbbbbb (1)
Document 1
+cccccc (1)
Document 2
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
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.
Have you looked at this one?
You can modify the script by changing line 32 from
to
Alexander
Sorry, I can’t get the solution above to work in SP2010.
//Robert
Hi, Sorry, but i have not ported all solutions to SP2010. I will try to find time, but i cannot promise anything.
Alexander
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
Hi,
Take a look here
Alexander
Is there a way to remove the group totals? E.g. “Matrices (2)” to just “Matrices”
Like this:
Alexander
Seems to have a problem with IE 7. Rest of browser things work fine.
So, this should suppress the group totals?
$(“td[class^=’ms-gb’]”).each(function(){
$(this).find(“span:last”).remove();
});
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
Is this SP2007 or SP2010?
Activate the “Console” in your browser by hitting F12 and look for errors – post your findings here.
Alexander
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
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
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;
}
});
});
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
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
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!
Do you know how this can be accomplished in SharePoint 2013?
This works like a charm, thank you!!!
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!
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.
Hi Guys,
I was checking this solution and looks great! Thank you Alexander!
I curious if it is possible also to color the categories, like the “tr” and maybe give different color to the items row in the category?
Something like can be done with the left navigation bar:
http://blogs.c5insight.com/Home/tabid/40/entryid/341/Create-an-Accordion-Navigation-for-SharePoint-2010-using-jQuery.aspx
Thanks,
Gabor
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.
I take it back. Somehow it doesn’t work now. Any idea?
It works simply with this:
#webpartID .ms-vb-title {}
instead of #WebPartWPQ7 table tr td table tr td.ms-vb2
Beware that several places in the code above are ‘smart’ quotes, like those in MS Word. Replace them with normal quotes and it will work just fine.
Any working solution for SP2013?
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