I got this request from Kale:
Do you have an ideas on how to remove “empty/blank” items when using the “group by” feature? See the example below. In other words, for category ‘Test 1′ you have to expand the blank item just to see the documents since they don’t have any subcategories assigned to them.
Example:
* Category: Test 1
* Subcategory 1:
– Document 1
– Document 2
* Category: Test 2
* Subcategory: SharePoint
– Document 3
– Document 4
* Subcategory: CRM
– Document 5
– Document 6This is how I want it to work:
* Category: Test 1
– Document 1
– Document 2
* Category: Test 2
* Subcategory: SharePoint
– Document 3
– Document 4
etc.Thanks!
Kale
This script checks if the “groupBy” is empty, and if so, expands the content of the group and hides the group header.
Add this script in a CEWP below the list view – alter the location of jQuery to reflect your location:
<script type="text/javascript" src="../../Javascript/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
// Add onclick to the first grouping
$(".ms-listviewtable td.ms-gb").click(function(){
expandEmptyCategory();
});
// Call function on load
isTbodyLoaded();
});
var isloadedCheck = 0;
// Looping function to call "expandEmptyCategory" when subgroups are loading - looping every 200ms for a maximum of 4 seconds
function isTbodyLoaded(){
setTimeout(function(){
tbodyIsLoadedLength = $(".ms-listviewtable tbody[isLoaded='true']").length;
if(tbodyIsLoadedLength>0){
expandEmptyCategory();
}else{
isloadedCheck += 1;
if(isloadedCheck<=20){
isTbodyLoaded();
}
}
},200);
}
function expandEmptyCategory(){
var NameGrouping2 = $(".ms-listviewtable td.ms-gb2:first a:eq(1)").text();
$(".ms-listviewtable td.ms-gb2").each(function(){
var grNameRaw = $(this).text().replace(NameGrouping2+' :','');
grName = grNameRaw.substring(0,grNameRaw.indexOf('(')-1).replace(/\s|\xA0/g,'');
if(grName.length==0){
var parentTbody = $(this).parents('tbody:first');
if(parentTbody.css('display')!='none'){
var tIdRaw = parentTbody.attr('id');
var tId = tIdRaw.substring(4);
var tb = $("#tbod"+tId+"_");
if(tb.attr('isLoaded')){
if(tb.css('display')=='none'){
$(this).find('a:first').click();
$(this).parents('tbody:first').hide();
}else{
$(this).parents('tbody:first').hide();
}
}
}
}
});
}
</script>
This solution is not fully tested so please post any bugs you might find.
Alexander
April 3, 2010 at 12:17 pm |
Hi Alex,
Thanks for useful post. I have the very same problem, but the above code doesn’t work for me at all.
Actually I couldn’t find any pages containing grouped list views or DVWP rendered by SharePoint to include “.ms-listviewtable” tags.
Would please explain more how to use this code?
Thank you in advance.
April 3, 2010 at 3:24 pm
Hi Amir,
The $(“.ms-listviewtable”) is used to locate the <TABLE> with class=”ms-listviewtable”.
The code is intended for a standard list view in a list or document library in SharePoint.
To use it with a DVWP you would have to modify the code. I have not tested it with a DVWP created in SharePoint designer myself.
Alexander
April 3, 2010 at 7:29 pm
Thank you Alexander for your reply.
Although couldn’t find the “.ms-listviewtable” class even for a standard grouped view, but I got the idea and trying to adapt it for DVWP, if successful will send you the code to share with other fellows.
March 7, 2011 at 4:50 am |
Hi, I have the same problem as well.
I have added the script to a CEWP below the document library’s list view on my page. However nothing has changed.
Any assistance you could offer would be appreciated!
Thanks
Emily
March 7, 2011 at 9:52 pm
Hi,
Do you get any error messages – like a yellow exclamation mark in the lower left corner in IE?
Alexander
May 11, 2011 at 8:15 pm |
Hi Alex,
Just wanted to let you know this solution worked for me with no issues.
I’m just wondering if you know if there is a way to (in addition to what your script is doing) also hide the label of the group (i.e. if I group by the column “Folder Name” I currently See “Folder Name: Folder1 (2)” Where I would like to see “Folder1 (2)”.
May 17, 2011 at 1:14 am |
when you say alter the jquery to reflect your location what do you mean? location as in the URL of the List being used?
May 17, 2011 at 7:46 am
Hi,
I mean the <script src=”…
Change it to the location of your local copy og jQuery, or use this link to Google’s script repository: https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js
Alexander
May 17, 2011 at 6:04 pm
thx for reply.
apologies for my ignorance but I am simply adding this to the source code of a Context Editor Web Part within the list and placing it below the list.
Even now with changed JQuery line nothing seems to happen? Is there anything else I need to do?
May 17, 2011 at 7:09 pm
Hi,
Are you using SP2007 or SP2010? – this solution has not been tested with 2010 yet.
Alexander
May 18, 2011 at 11:01 pm
SP2007. Also from looking at 1 of the other post replys I don’t have a yellow error on the page
May 25, 2011 at 7:18 pm
Hi,
If you emailed me a few screen shots i might see what’s wrong.
You find my email here
Alexander
December 9, 2011 at 10:53 am |
Hi,
Thanks for giving this solution its working for me, but only one problm when first click on group its not working, second click onwards its working. can any body solve this plz giv me the solution.
mahi
December 14, 2011 at 12:25 am
Hi,
Which browser (name and version) are you using?
Alexander
January 11, 2012 at 9:10 am |
HI i am using ie8 its working fine me, but only problm when we exapnd the groups then refresh page its not loading same state, because the expand function is writing in click event thats the problem please can u giv me the solution instead of click event.
I tried but its working for me.
Thnaks and advance apprecieated,
mahi……….
January 24, 2012 at 6:49 pm
Hi,
Try commenting out (removing) lines 20, 21 and 22.
Alexander