views:

22

answers:

2

I have a list in Sharepoint that contains a few hundred groupings. Some groupings only contain 1 row, and in those cases, I want to removing the grouping header above.

To do that, I think I need to hide all of the code (below) using jQuery. I want to make the logic so that it looks for the portion ">‎(1)", and if it finds that, it hides the hold TBODY. Any ideas? Not exactly sure how to start this.....

<TBODY id="titl1-2_" groupString=""><TR><TD colspan="100" class="ms-gb"  nowrap><img src="/_layouts/images/blank.gif" alt="" height=1 width=0><a href="javascript:" onclick="javascript:ExpCollGroup('1-2_','img_1-2_');return false;"><img id="img_1-2_" src="/_layouts/images/minus.gif" alt="Expand/Collapse" border="0"></a>&nbsp;<a href="javascript:" onclick="javascript:ExpCollGroup('1-2_','img_1-2_');return false;">Grouping1</a> :&nbsp;Accurint <span style="font-weight: lighter">&#8206;(1)</span></TD></TR></TBODY>
A: 

This might give you an idea:

$(document).ready(function() {
  $("tbody[id^='tit'] .ms-gb span").each(function() {
 //console.log("'" + $(this).text() + "'"); 
 if($(this).text().indexOf("(1)") > -1)
 {
  $(this).closest("tbody").hide(); // hides the header
 }
  });
});

This will be more complicate if your groups are expanded though. I recommend forcing them to be collapsed to avoid the trouble of finding the yet-to-be-created tbody container for the items.

F.Aquino
That worked, thanks! Alternatively, I was playing around with this and some sample code I have and I got the following to work. It could be the worst way to do this sort of thing, I have no idea.<script type="text/javascript">$(document).ready(function(){var RowOnly = $("TBODY span:contains('(1)')").each(function(){var HideParen1 = $(this);var HideName = $(this).parent();HideParen1.css("display", "none");HideName.css("display", "none");});});</script>
Brian
sounds OK. Also, hide() and show() are shortcuts to the css('display', ''). The 'tbody[id^='tit'] .ms-gb span' is made in order to have the least possible elements in the result, to help a bit with the performance
F.Aquino
A: 

That got messed up. The original answer worked. I also played around and got the following to work. It could be an awful way to do it, but it somehow worked with jQuery.

<script type="text/javascript">

$(document).ready(function(){

var RowOnly = $("TBODY span:contains('(1)')").each(function(){ var HideParen1 = $(this); var HideName = $(this).parent(); HideParen1.css("display", "none"); HideName.css("display", "none"); });

});

Brian