A while back I posted a tip about
hiding grouped by headers in list views. These are the content separators that appear at the top of a group of list items and have a +/- image for expanding/collapsing the group, the title of the group column, a colon and the group item name, like so:
+ Tasks: Testing
Many users, like myself, don’t like to see the column title in the header – they just want it to say ‘Testing’ with the expand/collapse icon. The most effective way to hide this element is to edit the CAML for the list view as I described in the original artice (which still applies in 2007 there are just more SCHEMA.XML files to edit); however, this only works on sites created AFTER the CAML has been changed. So what to do if you’ve already created a bunch of sites and want to correct this problem?
The easiest method (or at least the easiest that I could come up with) is to add some javascript to your master page(s) to find the offending text and hide it. There are really two parts to this: 1) isolate and remove the anchor tag with the column title, and 2) manipulate the HTML to get rid of the separating colon. Here’s the script:
<script type="text/javascript">
function RemoveGroupHeader()
{
var elements = document.getElementsByTagName("a");
for(var i=0; i<elements.length; i++)
{
if (elements[i].getAttribute(‘href’) == "javascript:" && elements[i].outerHTML.indexOf("ExpCollGroup") != -1)
{
var text = elements[i].parentNode.innerHTML;
var x = text.indexOf("</A> : ");
var y = x + 12;
var leadingText = text.substring(0, x + 4);
var trailingText = text.substring(y);
elements[i].parentNode.innerHTML = leadingText + trailingText;
if (elements[i].innerHTML.indexOf("Expand/Collapse") == -1)
{
elements[i].style.display = "none";
}
}
}
}
</script>
In a nutshell, this script loops through the collection of anchor tags on the page to find the ones which have the expand/collapse functionality. It then strips out the colon and hides the anchor tag with the column title. To invoke it, add it to the existing ‘onload’ function in the <body> tag of the page. Since there is likely to already be an onload event associated with each master page, you’ll need to append the RemoveGroupHeader() function, like so:
Original:
onload="javascript:_spBodyOnLoadWrapper();"
Modified:
onload="javascript:_spBodyOnLoadWrapper();RemoveGroupHeader();"
Voila! No more annoying column titles. Enjoy!
Is it possible to modify the code to have tool bar. So user can
add or update a lists from sub sites. I observed that this webpart allows to edit an item.
Have you guys intentionally blocked the add new entry?
Thanks,
Jess
Jess,
The answers to your quetions are 1) yes and 2) no. There are two ways to get the views published by a list – one is to retrieve the raw view XML and render it using XSL, which is what the built-in web parts do. This is a rather complext process, so I opted to use the second method to create the web part, which involves getting the sytem-defined HTML using SPView.RenderAsHTML() method.
Unfortunately, this method doesn’t return nice blocks of HTML that can easily be manipulated – things like the column headers, toolbars, and footers are either missing or completely mangled. The code primarily consists of string search and replace to get the views to render properly.
That being said, the ‘Add New…’ function could be added if the code base was expanded to include some additional OM methods and/or the raw xml via web services. There may also be some new methods in 2007 to make this a bit easier but I haven’t looked into them yet.
Thanks for the great solution to this annoying problem.
Also, I noticed that you’re running this blog on WSS 3.0. I’m part of the CKS:EBE project (http://www.codeplex.com/cks) and was wondering if you’ve posted the source code for the “email alerts” functionality you’ve added to this blog anywhere? If not, could you contribute it to the CKS project? It is really cool.
How do i remove hyper link from the testing? that would be helpful.