Search code examples
ag-gridag-grid-angular

How to disable row group expand functionality on one row?


After a lot of searches in SO without any particular solution, I am compelled to ask this question. What I want is to hide a row group icon on a single group row. Like in the below picture I have a group row that has only one record, which is already shown in the top row. I want to hide that collapse icon on that single record. Only collapse/expand icon shown when group rows are more than one.

For reference see AG-Grid Master-Detail Section, here they specify which rows to expand. Same functionality I needed here.

enter image description here

I'm using the below versions of AG-Grid Angular (v9)

"@ag-grid-community/core": "^25.3.0",
"@ag-grid-enterprise/row-grouping": "^26.0.0",
"@ag-grid-enterprise/server-side-row-model": "^25.3.0",
"ag-grid-angular": "^25.3.0",
"ag-grid-community": "^25.3.0",

Here is my code:

this.rowModelType = 'serverSide';
this.serverSideStoreType = 'partial';
this.cacheBlockSize = 20;
this.gridOptions = {
  rowData: this.loanlist,
  columnDefs: this.generateColumns(),
  getNodeChildDetails: function(rowItem) {
    if (rowItem.orderCount > 1) {
      return {
        expanded: true
      }
    } else {
      return null;
    }
  }
}

The issue is the getNodeChildDetails is not accessible. Browser console showing me the below warning and my above code is not working.

enter image description here


Solution

  • This is simple to achieve using a cellRendererSelector on the autoGroupColumnDef. You can specify whether to show the default agGroupCellRenderer or simply return another renderer (or, just return null):

        this.autoGroupColumnDef = {
          cellRendererSelector: (params) => {
            if (params.value == 'United States') {
              return null;
            } else {
              return {
                component: 'agGroupCellRenderer',
              };
            }
          },
        };
    

    In the example below, we are disabling the row group expand functionality on the United States row.

    See this implemented in the following plunkr.