You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ag-grid导出Excel:如何配置参数导出聚合行?

Ag-Grid导出Excel时包含聚合行的配置方法

我正在使用Ag-Grid,列定义中包含聚合行配置,希望启用Excel导出功能时同时导出聚合行,请问需要配置哪些参数才能实现?

原代码示例

this.gridApi.exportDataAsExcel(params) //<-------需要配置什么参数

//Ag-Grid列定义
columnDefs: [
        {
          field: "athlete",
          filter: "agTextColumnFilter",
          minWidth: 200
        },
        { field: "age",aggFunc:"sum" }, //<-------聚合列
        {
          field: "country",
          minWidth: 180
        },
        { field: "year" },
        {
          field: "date",
          minWidth: 150
        },
        { field: "gold", aggFunc:"sum" },//<-------聚合列
        { field: "silver", aggFunc:"sum" },//<-------聚合列
        { field: "bronze", aggFunc:"sum" },//<-------聚合列
        { field: "total", aggFunc:"sum" }//<-------聚合列
      ],

解决方案

要在Excel导出中包含聚合行,只需在exportDataAsExcel的参数对象中添加核心配置includeAggregationResults: true即可。如果你的聚合行是基于分组结构的,还可以配合includeGroups: true保留分组层级。

修改后的导出代码示例:

this.gridApi.exportDataAsExcel({
  includeAggregationResults: true,
  // 可选:需要导出所有列(含隐藏列)时添加
  // allColumns: true,
  // 分组场景下需保留分组结构时添加
  // includeGroups: true
});

参数说明

  • includeAggregationResults: true:强制Ag-Grid导出计算完成的聚合行数据
  • includeGroups: true:仅适用于分组表格,导出时保留分组层级与对应聚合行
  • allColumns: true:可选配置,默认仅导出当前可见列,开启后会导出所有列定义中的列

内容的提问来源于stack exchange,提问作者RV.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 07:54:10