Wednesday, 2 July 2014

Hiding List View Group Headers

Remove Group Names in Custom list
----------------------------------
_spBodyOnLoadFunctionNames.push("HideHeaders");
HideHeaders();
function HideHeaders()
{
var elements = getElementsByClassName(document, "td", "ms-gb");
var elem;
for(var i=0;i<elements.length;i++)
{
elem = elements[i];
elem.childNodes[3].style.display = "none";
elem.childNodes[4].nodeValue = elem.childNodes[4].nodeValue.replace(':', '');
}
}
function getElementsByClassName(oElm, strTagName, strClassName){
var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
var arrReturnElements = new Array();
strClassName = strClassName.replace(/\-/g, "\\-");
var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
var oElement;
for(var i=0; i<arrElements.length; i++){
oElement = arrElements[i];
if(oRegExp.test(oElement.className)){
arrReturnElements.push(oElement);
}
}
return (arrReturnElements)
}
=========================================================
Remove Group Names in custom list sub groups also
--------------------------------------------------
_spBodyOnLoadFunctionNames.push("HideHeaders");
function HideHeaders()
{
var elements = getElementsByClassName(document, "td", "ms-gb");
var elem;
for(var i=0;i<elements.length;i++)
{
elem = elements[i];
elem.childNodes[3].style.display = "none";
elem.childNodes[4].nodeValue = elem.childNodes[4].nodeValue.replace(':', '');
}
elements = getElementsByClassName(document, "td", "ms-gb2");
for(var i=0;i<elements.length;i++)
{
elem = elements[i];
elem.childNodes[3].style.display = "none";
elem.childNodes[4].nodeValue = elem.childNodes[4].nodeValue.replace(':', '');
}
elements = getElementsByClassName(document, "tr", "ms-viewheadertr");
for(var i=0;i<elements.length;i++)
{
elem = elements[i];
elem.style.display = "none";
}
}
function getElementsByClassName(oElm, strTagName, strClassName){
var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
var arrReturnElements = new Array();
strClassName = strClassName.replace(/\-/g, "\\-");
var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
var oElement;
for(var i=0; i<arrElements.length; i++){
oElement = arrElements[i];
if(oRegExp.test(oElement.className)){
arrReturnElements.push(oElement);
}
}
return (arrReturnElements)
}
=======================================================
(OR)
========================================================
_spBodyOnLoadFunctionNames.push("HideHeaders");
function HideHeaders()
{
var elements = getElementsByClassName(document, "td", "ms-gb");
var elem;
for(var i=0;i<elements.length;i++)
{
elem = elements[i];
elem.childNodes[3].style.display = "none";
elem.removeChild(elem.childNodes[4]);
}
elements = getElementsByClassName(document, "td", "ms-gb2");
for(var i=0;i<elements.length;i++)
{
elem = elements[i];
elem.childNodes[3].style.display = "none";
elem.removeChild(elem.childNodes[4]);
}
elements = getElementsByClassName(document, "tr", "ms-viewheadertr");
for(var i=0;i<elements.length;i++)
{
elem = elements[i];
elem.style.display = "none";
}
}
function getElementsByClassName(oElm, strTagName, strClassName){
var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
var arrReturnElements = new Array();
strClassName = strClassName.replace(/\-/g, "\\-");
var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
var oElement;
for(var i=0; i<arrElements.length; i++){
oElement = arrElements[i];
if(oRegExp.test(oElement.className)){
arrReturnElements.push(oElement);
}
}
return (arrReturnElements)
}