Group totals in SPGridView

When I group elements in SPGridView using the GroupField property, grouping works fine, but the total number of rows does not appear, as in the standard SharePoint list. Typically, SharePoint displays the counter next to the group in brackets (i.e. Group 1 (5)). Is there any way to enable this functionality.

+4
source share
5 answers

Have you tried setting the DisplayGroupFieldName property to True ?

SPGridView Class Documentation

0
source

I quickly looked through the code and even overriding SPGridview does not seem to have a simple hook for this.

You may be able to create Javascript, but it will be far from interesting.

0
source

Javascript works! Nat's help helped me!

See the jquery example below:

 $(".ms-gb td:contains('" + groupName + "')") .append("<div class='stat'>text</div>") 
0
source

If you do not want to use javascript, you can iterate through the table and count the rows in each group.

The downside is that you will probably need to count all the lines, and then go back and update the group name on each line.

For instance:

 ID Value Group 1 One GroupA 2 Two GroupA 3 Three GroupB 4 Four GroupB 5 Five GroupB 

2 in GroupA
3 in GroupB

 ID Value Group 1 One GroupA (2) 2 Two GroupA (2) 3 Three GroupB (3) 4 Four GroupB (3) 5 Five GroupB (3) 
0
source

I know this question is old, but anyway:

 var rows = document.getElementById("your_table").getElementsByTagName("TR"); for (var i = 0; i < rows.length; i++) { if (rows[i].className == 'ms-gb') { var count = 0; var el = rows[i].nextSibling; while (el) { if (el.className != 'ms-gb') count++; else break; el = el.nextSibling; } rows[i].children[0].innerHTML += " <span dir='ltr'>(" + count + ")</span>"; } } 

You can drop.getElementById ("your_table") if you want to apply it to the entire page anyway, otherwise put the gridview in the control with this identifier.

-1
source

All Articles