This topic explains how to use the API for expanding and collapsing child grids in igHierarchicalGrid™.
The following topics are required as a prerequisite to understanding this topic.
This topic contains the following sections:
The following table lists the configurable aspects of the igHierarchicalGrid control related to expanding and collapsing rows.
Configurable aspects | Methods |
---|---|
Expanding rows | |
Collapsing rows | |
Toggle rows |
The following table lists the code examples included in this topic.
Example | Description |
---|---|
Code Example: Expanding All Rows on a Parent Grid | Shows how to expand all rows of the root grid. |
Code Example: Collapsing All Rows on a Parent Grid | Shows how to collapse all rows of the root grid. |
Code Example: Toggling the Current Selected Row | Shows how to toggle the current selected row of the root grid. |
This example shows how to expand all rows of the root grid. In the example below the following functions are defined:
expandAllRowsOfGrid
: this function expands all rows of the grid which is passed to it. The function can be used on any level of the hierarchy.expandAllRowsOfRootGrid
: this function expands all rows of the root grid. The function gets the reference to top level grid and then passes it to expandAllRowsOfGrid
.In Javascript:
function expandAllRowsOfGrid(grid) {
// expand each row in grid
$(grid.allRows()).each(function (index, element) {
$("#grid1").igHierarchicalGrid("expand", element);
});
}
function expandAllRowsOfRootGrid() {
// get the top level grid
var parentGrid = $("#grid1").igHierarchicalGrid("rootWidget");
expandAllRowsOfGrid(parentGrid);
}
This example shows how to collapse all rows of the root grid. In the example below the following functions are defined:
collapseAllRowsOfGrid
: this function collapses all rows of the grid which is passed to it. This function can be used on any level of the hierarchy.collapseAllRowsOfRootGrid
: this function collapses all rows of the root grid. The function gets the reference to top level grid and then passes it to collapseAllRowsOfGrid.In Javascript:
function collapseAllRowsOfGrid(grid) {
// collapse each row
$(grid.allRows()).each(function (index, element) {
$("#grid1").igHierarchicalGrid("collapse", element);
});
}
function collapseAllRowsOfRootGrid() {
// get the top level grid
var parentGrid = $("#grid1").igHierarchicalGrid("rootWidget");
collapseAllRowsOfGrid(parentGrid);
}
This example shows how to toggle the current selected row of the root grid. In the example below the following functions are defined:
toggleCurrentRowOfGrid
: this function toggles current row of the grid which is passed to it. The function can be used on any level of the hierarchy.toggleCurrentRowOfRootGrid
: this function toggles current row of the root grid. The function gets the reference to top level grid and then passes it to toggleCurrentRowOfGrid
.Note: For this example to work the
Selection
feature must be enabled.
In Javascript:
function toggleCurrentRowOfGrid(grid) {
// get reference to current selected row
var row = $(grid).igGridSelection("selectedRow");
if (row) {
// toggle row
$("#grid1").igHierarchicalGrid("toggle", row.element);
}
}
function toggleCurrentRowOfRootGrid(grid) {
// get the top level grid
var parentGrid = $("#grid1").igHierarchicalGrid("root");
toggleCurrentRowOfGrid(parentGrid);
}
The following topics provide additional information related to this topic.
View on GitHub