Sharepoint SPGridView control is expanded by default

The Sharepoint SPGridView control seems to be rendered as expanded sometimes, although it should be collapsed.

Here is a javascript function to fix this issue:

function spGridViewFixExpandedGroups(gridviewId) {
    var gridview = $("[id$='" + gridviewId + "']");
    var links = gridview.find("tr[isexp='true'] a[title='Expand/Collapse']");
    links.click();
}

Simply call the script upon page load. Note: The script requires the jQuery library to be included.

2 Responses to “Sharepoint SPGridView control is expanded by default”


  1. 1 Trilochan Nayak February 17, 2012 at 10:18 am

    It solved my problem

  2. 2 Sagar Sontakke August 18, 2015 at 11:58 am

    If you have DisplayGroupFieldName enabled in SPGridView then, you need to change line to below to get this work:-
    var links = gridview.find(“tr”).find(“a[title*=’Expand/Collapse’]”)

    Note after title *= instead of only =

    —————————————————

    I’ve modified this function as below to work in my case:-

    function spGridViewFixExpandedGroups(gridviewId) {
    var gridview = $(“[id$='” + gridviewId + “‘]”);
    /*var links = gridview.find(“tr[isexp=’true’]”).find(“a[title*=’Expand/Collapse’]”);*/
    var links = gridview.find(“tr”).find(“a[title*=’Expand/Collapse’]”);
    links.click();
    }

    —————————————————


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: