PANVEGA’s Blog

DotNet Development, SharePoint Customizing, Silverlight, MS Infrastructure and other tips and tricks

Fixing ExpGroupBy in Core.js for Firefox

Posted by PANVEGA on December 9, 2007

Szenario:

When converting a view grouped by some field (ListViewWebPart) to a custom XSLT Data View (DataFormWebPart) using the Sharepoint Designer, the “plus” image to expand / collapse groups doesn’t work anymore in Firefox (works fine in IE).

I made a data view web part for a recruiting page for different available jobs that used grouping, but the expand/collapse groups did not work in FireFox. The first line of the script stops FF from running the script but there’s no real reason.

These are the steps to reproduce:

  1. create a new view (from website)
  2. group by any field (in my case, Created by)
  3. in sharepoint designer, open the aspx page corresponding to the view
  4. right click on the list (ListViewWebPart) and choose “Convert to XSTL Data View” (creates DataFormWebPart)
  5. open the page in Firefox

The script called is function ExpGroupBy in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\1036\Core.js. The javascript in core.js that expands and collapses the grouped sections did not work in FireFox.  I suggest, for a quick fix on a single page, add a Content Editor Web Part with the new function like I have below; set the web part to “hidden.”

Here is the adujsted JavaScript function for Firefox:

<![CDATA[
function ExpGroupBy(formObj)
{
if ((browseris.w3c) && (!browseris.ie)) {
document.all=document.getElementsByTagName(“*”);
}

docElts=document.all;
numElts=docElts.length;
images=formObj.getElementsByTagName(“IMG”);
img=images[0];
srcPath=img.src;
index=srcPath.lastIndexOf(“/”);
imgName=srcPath.slice(index+1);
if (imgName==’plus.gif’)
{
fOpen=true;
displayStr=””;
img.src=’/_layouts/images/minus.gif’;
}
else
{
fOpen=false;
displayStr=”none”;
img.src=’/_layouts/images/plus.gif’;
}
oldName=img.name;
img.name=img.alt;
img.alt=oldName;
spanNode=img;
while(spanNode !=null)
{
spanNode=spanNode.parentNode;
if (spanNode !=null &&
spanNode.id !=null &&
spanNode.id.length > 5 &&
spanNode.id.substr(0, 5)==”group”)
break;
}
parentNode=spanNode;
while(parentNode !=null)
{
parentNode=parentNode.parentNode;
if (parentNode !=null &&
parentNode.tagName==”TABLE”)
break;
}
lastNode=null;
if (parentNode !=null)
{
lastNode=parentNode.lastChild;
if (lastNode !=null && lastNode.tagName==”TBODY”)
lastNode=lastNode.lastChild;
if (lastNode !=null && lastNode.tagName==”TR” && lastNode.lastChild !=null)
lastNode=lastNode.lastChild;
}
for(var i=0;i<numElts;i++)
{
var childObj=docElts[i];
if (childObj==spanNode)
break;
}
ID=spanNode.id.slice(5);
for(var j=i+1; j<numElts; j++)
{
var childObj=docElts[j];
if (childObj.id.length > 5 &&
childObj.id.substr(0, 5)==”group”)
{
curID=childObj.id.slice(5);
if (curID <=ID)
return;
}
parentNode=childObj;
while(parentNode !=null)
{
parentNode=parentNode.parentElement;
if (parentNode==spanNode)
break;
}
if (parentNode==spanNode)
continue;
if (childObj !=img &&
childObj.tagName==”IMG” &&
childObj.src &&
childObj.src.slice(childObj.src.length – 25)==’/_layouts/images/plus.gif’)
{
childObj.src=’/_layouts/images/minus.gif’;
oldName=childObj.name;
childObj.name=childObj.alt;
childObj.alt=oldName;
}
if (childObj.tagName==spanNode.tagName &&
childObj.id !=”footer”)
{
childObj.style.display=displayStr;
}
if ((childObj.tagName==”TABLE” && lastNode==null) || childObj==lastNode)
break;
}
}
]]>

Thats all you have to do. Good Luck

Advertisements

6 Responses to “Fixing ExpGroupBy in Core.js for Firefox”

  1. saurav said

    Thanks man..U save my lots of work..

  2. Leila said

    Hi

    I did it. But it doesn’t work :(

  3. Leila said

    I found the following script and it worked for me :

    function ExpGroupBy(formObj)
    {
    if ((browseris.w3c) && (!browseris.ie)) {
    document.all=document.getElementsByTagName(“*”);
    }

    docElts=document.all;
    numElts=docElts.length;
    images=formObj.getElementsByTagName(“IMG”);
    img=images[0];
    srcPath=img.src;
    index=srcPath.lastIndexOf(”/”);
    imgName=srcPath.slice(index+1);
    if (imgName==’plus.gif’)
    {
    fOpen=true;
    displayStr=””;
    img.src=’/_layouts/images/minus.gif’;
    }
    else
    {
    fOpen=false;
    displayStr=”none”;
    img.src=’/_layouts/images/plus.gif’;
    }
    oldName=img.name;
    img.name=img.alt;
    img.alt=oldName;
    spanNode=img;
    while(spanNode !=null)
    {
    spanNode=spanNode.parentNode;
    if (spanNode !=null &&
    spanNode.id !=null &&
    spanNode.id.length > 5 &&
    spanNode.id.substr(0, 5)==”group”)
    break;
    }
    parentNode=spanNode;
    while(parentNode !=null)
    {
    parentNode=parentNode.parentNode;
    if (parentNode !=null &&
    parentNode.tagName==”TABLE”)
    break;
    }
    lastNode=null;
    if (parentNode !=null)
    {
    lastNode=parentNode.lastChild;
    if (lastNode !=null && lastNode.tagName==”TBODY”)
    lastNode=lastNode.lastChild;
    if (lastNode !=null && lastNode.tagName==”TR” && lastNode.lastChild !=null)
    lastNode=lastNode.lastChild;
    }
    for(var i=0;i<numElts;i++)
    {
    var childObj=docElts[i];
    if (childObj==spanNode)
    break;
    }
    ID=spanNode.id.slice(5);
    for(var j=i+1; j 5 &&
    childObj.id.substr(0, 5)==”group”)
    {
    curID=childObj.id.slice(5);
    if (curID <=ID)
    return;
    }
    parentNode=childObj;
    while(parentNode !=null)
    {
    parentNode=parentNode.parentElement;
    if (parentNode==spanNode)
    break;
    }
    if (parentNode==spanNode)
    continue;
    if (childObj !=img &&
    childObj.tagName==”IMG” &&
    childObj.src &&
    childObj.src.slice(childObj.src.length – 25)==’/_layouts/images/plus.gif’)
    {
    childObj.src=’/_layouts/images/minus.gif’;
    oldName=childObj.name;
    childObj.name=childObj.alt;
    childObj.alt=oldName;
    }
    if (childObj.tagName==spanNode.tagName &&
    childObj.id !=”footer”)
    {
    childObj.style.display=displayStr;
    }
    if ((childObj.tagName==”TABLE” && lastNode==null) || childObj==lastNode)
    break;
    }
    }

  4. Dominic said

    Hi

    We have been using this code and it works very well. Unfortunately in the latest version of firefox 3.5.5 the code stop working.

    Can you suggest anything we can do to fix this.

  5. Christina said

    Hi,

    I have the same problem as Dominic. The expand/collaps fix didn´t work for the latest firefox version. Has anybody solved this problem?

  6. Leila said

    Hi
    Has anybody solved this problem?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: