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
September 2, 2011 at 6:02 pm |
Hi Alexander,
YOU ARE THE BOSS
)
Just tested and it works like a charm
))
Thanks for your help !!
Best personal regards
Djamel
September 8, 2011 at 6:16 pm |
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.
September 8, 2011 at 11:14 pm
Hi,
Remember to put the CEWP below the list view web part.
Alexander
September 28, 2011 at 12:19 pm |
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
September 28, 2011 at 1:21 pm
Sorry, in the “After”-list it’s supposed to look like this:
+aaaaaa (1)
+bbbbbb (1)
Document 1
+cccccc (1)
Document 2
October 7, 2011 at 11:38 pm
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
October 8, 2011 at 9:54 am
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.
October 8, 2011 at 6:40 pm
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
October 10, 2011 at 8:10 am
Sorry, I can’t get the solution above to work in SP2010.
//Robert
October 27, 2011 at 3:40 pm
Hi, Sorry, but i have not ported all solutions to SP2010. I will try to find time, but i cannot promise anything.
Alexander
October 15, 2011 at 2:06 pm |
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
October 27, 2011 at 11:35 pm
Hi,
Take a look here
Alexander
October 20, 2011 at 10:59 pm |
Is there a way to remove the group totals? E.g. “Matrices (2)” to just “Matrices”
October 29, 2011 at 12:12 am
Like this:
$("td[class^='ms-gb']").each(function(){ $(this).find("span:last").remove(); });Alexander
February 15, 2012 at 7:24 pm |
Seems to have a problem with IE 7. Rest of browser things work fine.
February 24, 2012 at 9:17 pm |
So, this should suppress the group totals?
$(“td[class^='ms-gb']“).each(function(){
$(this).find(“span:last”).remove();
});
February 24, 2012 at 9:23 pm |
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
March 4, 2012 at 11:38 pm
Is this SP2007 or SP2010?
Activate the “Console” in your browser by hitting F12 and look for errors – post your findings here.
Alexander