Expanding and Collapsing Rows in Syncfusion GridGroupingControl

Applies to TestComplete 15.63, last modified on April 23, 2024

Syncfusion GridGroupingControl supports hierarchical data representation. If the grid displays data of multiple nested data tables, then each data row can have child rows containing data associated with this row. To view the child data, the user needs to expand its parent row and the child table itself. The grid data can also be grouped by one or several columns, so the individual rows are organized into groups. This topic explains how you can expand and collapse rows and groups in the GridGroupingControl from your test scripts:

To perform these actions, TestComplete should have access to internal objects, properties and methods of the GridGroupingControl object. For this purpose, the .NET Application Support and Syncfusion Systems Control Support plugins must be installed and enabled. The latter lets you work with the GridGroupingControl controls using methods and properties of the SyncfusionEssGrid object. Without this plugin, you will not be able to work with controls using their internal methods and properties.

When testing Syncfusion GridGroupingControl controls, use specific methods and properties of the corresponding SyncfusionEssGrid object. You can call these methods and properties from your keyword tests, as well as from scripts. This topic describes how to work with an object’s properties and methods from your scripts. However, when testing a GridGroupingControl control from your keyword test, you can use the same methods and properties calling them from keyword test operations. For more information, see Keyword Tests Basic Operations.

Using the SyncfusionEssGrid.Expand and Collapse Actions

The SyncfusionEssGrid object provides a number of Expand and Collapse actions that can be used to expand and collapse various types of items in the Syncfusion GridGroupingControl:

The following example illustrates how you can expand and collapse rows, groups and tables in Syncfusion GridGrouping control using the mentioned actions. This example works with the HierarchySample application that comes with the Syncfusion Essential Studio library.

JavaScript, JScript

function Main ()
{
  var p, Grid;
  // Obtain the grid object
  p = Sys.Process("HierarchySample");
  p.WinFormsObject("Form1").Maximize();
  Grid = p.WinFormsObject("Form1").WinFormsObject("groupingGrid1");

  // Collapse items in the last row
  Grid.wChildView(7, "Products").CollapseGroup(3);
  Grid.CollapseChildView(7, "Products");
  Grid.Collapse(7);

  // Expand 1st elements in the 1nd row
  Grid.Expand(0);
  Grid.ExpandChildView(0, "Products");
  Grid.wChildView(0, "Products").ExpandGroup(0);
  Grid.wChildView(0, "Products").wGroup(0).Expand(0);
  Grid.wChildView(0, "Products").wGroup(0).ExpandChildView(0, "OrderDetails");
  Grid.wChildView(0, "Products").wGroup(0).wChildView(0, "OrderDetails").ExpandGroup(0);
}

Python

def Main ():
  # Obtain the grid object
  p = Sys.Process("HierarchySample")
  p.WinFormsObject("Form1").Maximize()
  Grid = p.WinFormsObject("Form1").WinFormsObject("groupingGrid1")

  # Collapse items in the last row
  Grid.wChildView(7, "Products").CollapseGroup(3)
  Grid.CollapseChildView(7, "Products")
  Grid.Collapse(7)

  # Expand 1st elements in the 1nd row
  Grid.Expand(0)
  Grid.ExpandChildView(0, "Products")
  Grid.wChildView(0, "Products").ExpandGroup(0)
  Grid.wChildView(0, "Products").wGroup(0).Expand(0)
  Grid.wChildView(0, "Products").wGroup(0).ExpandChildView(0, "OrderDetails")
  Grid.wChildView(0, "Products").wGroup(0).wChildView(0, "OrderDetails").ExpandGroup(0)

VBScript

Sub Main
  Dim p, Grid
  ' Obtain the grid object
  Set p = Sys.Process("HierarchySample")
  p.WinFormsObject("Form1").Maximize
  Set Grid = p.WinFormsObject("Form1").WinFormsObject("groupingGrid1")

  ' Collapse items in the last row
  Grid.wChildView(7, "Products").CollapseGroup(3)
  Call Grid.CollapseChildView(7, "Products")
  Grid.Collapse(7)

  ' Expand 1st elements in the 1nd row
  Grid.Expand(0)
  Call Grid.ExpandChildView(0, "Products")
  Grid.wChildView(0, "Products").ExpandGroup(0)
  Grid.wChildView(0, "Products").wGroup(0).Expand(0)
  Call Grid.wChildView(0, "Products").wGroup(0).ExpandChildView(0, "OrderDetails")
  Grid.wChildView(0, "Products").wGroup(0).wChildView(0, "OrderDetails").ExpandGroup(0)
End Sub

DelphiScript

procedure Main;
var p, Grid : OleVariant;
begin
  // Obtain the grid object
  p := Sys.Process('HierarchySample');
  p.WinFormsObject('Form1').Maximize;
  Grid := p.WinFormsObject('Form1').WinFormsObject('groupingGrid1');

  // Collapse items in the last row
  Grid.wChildView[7, 'Products'].CollapseGroup(3);
  Grid.CollapseChildView(7, 'Products');
  Grid.Collapse(7);

  // Expand 1st elements in the 1nd row
  Grid.Expand(0);
  Grid.ExpandChildView(0, 'Products');
  Grid.wChildView[0, 'Products'].ExpandGroup(0);
  Grid.wChildView[0, 'Products'].wGroup[0].Expand(0);
  Grid.wChildView[0, 'Products'].wGroup[0].ExpandChildView(0, 'OrderDetails');
  Grid.wChildView[0, 'Products'].wGroup[0].wChildView[0, 'OrderDetails'].ExpandGroup(0);
end;

C++Script, C#Script

function Main ()
{
  var p, Grid;
  // Obtain the grid object
  p = Sys["Process"]("HierarchySample");
  p["WinFormsObject"]("Form1")["Maximize"]();
  Grid = p["WinFormsObject"]("Form1")["WinFormsObject"]("groupingGrid1");

  // Collapse items in the last row
  Grid["wChildView"](7, "Products")["CollapseGroup"](3);
  Grid["CollapseChildView"](7, "Products");
  Grid["Collapse"](7);

  // Expand 1st elements in the 1nd row
  Grid["Expand"](0);
  Grid["ExpandChildView"](0, "Products");
  Grid["wChildView"](0, "Products")["ExpandGroup"](0);
  Grid["wChildView"](0, "Products")["wGroup"](0)["Expand"](0);
  Grid["wChildView"](0, "Products")["wGroup"](0)["ExpandChildView"](0, "OrderDetails");
  Grid["wChildView"](0, "Products")["wGroup"](0)["wChildView"](0, "OrderDetails")["ExpandGroup"](0);
}

Using the GridGroupingControl Internal Methods

To expand and collapse all rows and groups in the grid at once, you can either create special functions that will recursively call the Expand and Collapse actions for all grid elements, or you can use the GridGroupingControl internal methods. These methods are listed in the table below:

Method Description
GridObj.Table.ExpandAllGroups() Expands all groups in the grid.
GridObj.Table.CollapseAllGroups() Collapses all groups in the grid.
GridObj.Table.ExpandAllRecords() Expands all data rows, groups and child tables in the grid.
GridObj.Table.CollapseAllRecords() Collapses all data rows, groups and child tables in the grid.

The following example contains the sample ExpandAll and CollapseAll routines that can be used to recursively expand or collapse all rows, groups and child tables in GridGroupingControl. The Grid parameter of these routines specify the GridGroupingControl control under test.

This example demonstrates how you can use these methods to expand/collapse all items in the GridGroupingControl grid.

JavaScript, JScript

function Main ()
{
  var p, Grid;
  // Obtain the grid object
  p = Sys.Process("HierarchySample");
  p.WinFormsObject("Form1").Maximize();
  Grid = p.WinFormsObject("Form1").WinFormsObject("groupingGrid1");

  CollapseAll (Grid);

  aqUtils.Delay (1000);

  ExpandAll (Grid);
}

function ExpandAll (Grid)
{
  Grid.Table.ExpandAllRecords();
}

function CollapseAll (Grid)
{
  Grid.Table.CollapseAllRecords();
}

Python

def Main ():
  # Obtain the grid object
  p = Sys.Process("HierarchySample")
  p.WinFormsObject("Form1").Maximize()
  Grid = p.WinFormsObject("Form1").WinFormsObject("groupingGrid1")

  CollapseAll (Grid)

  aqUtils.Delay (1000)

  ExpandAll (Grid)

def ExpandAll (Grid):
  Grid.Table.ExpandAllRecords()

def CollapseAll (Grid):
  Grid.Table.CollapseAllRecords()

VBScript

Sub Main
  Dim p, Grid
  ' Obtain the grid object
  Set p = Sys.Process("HierarchySample")
  p.WinFormsObject("Form1").Maximize
  Set Grid = p.WinFormsObject("Form1").WinFormsObject("groupingGrid1")

  CollapseAll Grid
  
  aqUtils.Delay 1000

  ExpandAll Grid
End Sub

Sub ExpandAll (Grid)
  Grid.Table.ExpandAllRecords
End Sub

Sub CollapseAll (Grid)
  Grid.Table.CollapseAllRecords
End Sub

DelphiScript

procedure ExpandAll (Grid);
begin
  Grid.Table.ExpandAllRecords;
end;

procedure CollapseAll (Grid);
begin
  Grid.Table.CollapseAllRecords;
end;

procedure Main;
var p, Grid : OleVariant;
begin
  // Obtain the grid object
  p := Sys.Process('HierarchySample');
  p.WinFormsObject('Form1').Maximize;
  Grid := p.WinFormsObject('Form1').WinFormsObject('groupingGrid1');

  CollapseAll (Grid);
  
  aqUtils.Delay (1000);

  ExpandAll (Grid);
end;

C++Script, C#Script

function Main ()
{
  var p, Grid;
  // Obtain the grid object
  p = Sys["Process"]("HierarchySample");
  p.WinFormsObject("Form1").Maximize();
  Grid = p["WinFormsObject"]("Form1")["WinFormsObject"]("groupingGrid1");

  CollapseAll (Grid);

  aqUtils["Delay"] (1000);

  ExpandAll (Grid);
}

function ExpandAll (Grid)
{
  Grid["Table"]["ExpandAllRecords"]();
}

function CollapseAll (Grid)
{
  Grid["Table"]["CollapseAllRecords"]();
}

See Also

Working With Syncfusion GridGroupingControl
Collapse Action (Grid Controls)
CollapseChildView Action (Specific to SyncfusionEssGrid Controls)
CollapseGroup Action (Grid Controls)
Expand Action (Grid Controls)
ExpandChildView Action (Specific to SyncfusionEssGrid Controls)
ExpandGroup Action (Grid Controls)

Highlight search results