Ag-grid: 如何在使用 AggFunc 时更改定义列标题名称?

Ag-grid: How to change define column headerName when using AggFunc?

对于给定的列定义,当使用 aggFunc 时,headerName 以 func(string) 格式出现 - 我只希望 header 显示我定义的字符串。当 AggFunc 为 null 时,此行为不存在。

const  columnDef: any = {

    headerName: 'Test',
    field: date,
    suppressMenu: true,
    width: 80,
    editable: true,
    lockPosition: true,
    type: 'numericColumn',
    aggFunc: function(data) {

      let sum = 0;
      data.forEach( function(value) {
        if (value) {
            sum = sum + parseFloat(value);
          }
      } );
      if (!sum) { return null; }

      return sum.toFixed(2);
    },
}

header名称应该是 "test",但会显示 func(test)。

https://imgur.com/a/mJoM5tw

您需要在 gridOptions 中将此 属性 标记为 true。

suppressAggFuncInHeader : true;

根据文档-

When true, column headers won't include the aggFunc, eg 'sum(Bank Balance)' will just be 'Bank Balance'.