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.
Advertisement
0 Responses to “Sharepoint SPGridView, expand specific group using Javascript”