1
votes

I have an ag-grid master-detail grid in my Angular 8 application, where one master row has only 1 sub-row in the detail grid. I am using "ag-grid-enterprise": "^21.0.1". All is working fine except:

  1. Export to excel does not export the "detail" grid in version 21 but works file in version 22. I did not find any documentation to support this.
  2. Export to excel exports the "Detail" grid below the "Master" grid in the excel. Is there a way to have all the "Master" and "Details" headers in the same row in the excel?
  3. Expand of any master row existing expanded rows should collapse. There should be only single master detail row should be expanded. This looks like a basic feature but I did not see it in any of the examples or documentation.
1

1 Answers

0
votes

Exporting master-detail data, you'll need to configure this in gridOptions and tell it when to export. For example:

this.defaultExportParams = {
      getCustomContentBelowRow: function(params) {
        return [
          [
            cell(''),
            cell('Call Id', 'header'),
            cell('Direction', 'header'),
            cell('Number', 'header'),
            cell('Duration', 'header'),
            cell('Switch Code', 'header'),
          ],
        ].concat(
          params.node.data.callRecords.map(function(record) {
            return [
              cell(''),
              cell(record.callId, 'body'),
              cell(record.direction, 'body'),
              cell(record.number, 'body'),
              cell(record.duration, 'body'),
              cell(record.switchCode, 'body'),
            ];
          }),
          [[]]
        );
      },
      columnWidth: 120,
    }

The above code will ensure you export the detail, but you'll need to configure the columns. Here is the documentation for this.

As for your third question, you can use the getDetailRowData callback to collapse all other details like this:

getDetailRowData: function(params) {
        this.gridApi.forEachNode(node => {
          node.expanded = false;
        });
        params.successCallback(params.data.callRecords);
      }.bind(this),

Take a look at this Plunker.