Prasad Bolla's SharePoint Blog

Click Here to go through the Interesting posts within my Blog.

Click Here to go through the new posts in my blog.

Sunday, December 04, 2011

SpGridView GroupBy Problem

When you implement a group by by default all groups will be in Expanded Mode. This is a bug with SpGridView. If You keep the below scripy within your WebPart page then by default SpGridview will collapse all the Group By's to Collapsed Mode.
function ShowCollapsed()
{
 var rows = document.getElementsByTagName('tr');
 var numRows = rows.length;
 for (var i = 0; i < numRows; ++i)
 {
    if (rows[i].getAttribute("isexp") != null &&
rows[i].getAttribute("isexp").toLowerCase() == "true")
    {
          if(rows[i].firstChild.firstChild != null &&
rows[i].firstChild.firstChild.tagName.toLowerCase() == "a")
          {
              if (rows[i].firstChild.firstChild.title.toLowerCase() ==
"expand/collapse")
                  {
                    rows[i].firstChild.firstChild.fireEvent("onclick");
                  }
          }
     }

  }
}
_spBodyOnLoadFunctionNames.push("ShowCollapsed");

No comments:

Post a Comment