Search code examples
ag-gridag-grid-angular

How to expand rows in grouped data in Ag-grid angular?


I want to expand particular rows in table,on certain condition. But i actually want it during on-load of page, not on any click events.

The solutions i saw online are based on click events.

Can any one help me on it?


Solution

  • Listen to the gridReady event:

    <ag-grid-angular [gridOptions]="gridOptions" (gridReady)="gridReady($event)"></ag-grid-angular>
    

    And then loop though the nodes and determine whether or not you want it expanded:

    gridReady = (params) => { 
       gridOptions.api.setData([yourData]);
       gridOptions.api.forEachNode(function(node) {
         // enter your expansion criteria here
         if (node.key==='whatever') {
            node.setExpanded(true);
         }
       });
    }