Sharepoint SPGridView, expand specific group using Javascript

Sometimes you want to expand a specific group within a SPGridView using Javascript.

The following function achieves just that:

function spGridViewExpandViewGroup(gridviewId, groupIndex) {

    var gridview = $("[id$='" + gridviewId + "']");
    var rows = gridview.find("tr[isexp]");

    if (rows.length >= groupIndex) {
        var row = rows.get(groupIndex);
        
        if ($(row).attr('isexp') == 'false') {
            var link = $(row).find("a[title='Expand/Collapse']");
            link.click();
        }
    }
}

Basically you pass in the (serverside) ID of the SPGridView control and the index of the group that should be expanded.

As example, the function call being contructed on the asp.net side:

string javaScript = string.Format("spGridViewExpandViewGroup('{0}',{1});", gridView.ID, 0);
Page.ClientScript.RegisterStartupScript(typeof(string), "expandviewgroup", javaScript, true);

Note: The script requires the jQuery library to be included.

About these ads

1 Response to “Sharepoint SPGridView, expand specific group using Javascript”


  1. 1 คาสิโนออนไลน์ January 11, 2014 at 2:39 pm

    This excellent website definitely has all of the information and facts I wanted concerning this subject and didn’t know who to ask.


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





Follow

Get every new post delivered to your Inbox.

%d bloggers like this: