Javascript 如何在ag网格的页脚中显示特定的列总和

Javascript 如何在ag网格的页脚中显示特定的列总和,javascript,ag-grid,Javascript,Ag Grid,如何在ag表格的页脚显示特定列的总和。 例如,如果我在ag grid表格中有列名称salary,那么我想在网格底部显示工资总额,如下图所示。您可以使用AgGrid文档部分中讨论的grid属性 使用问题中的列,您可以执行以下操作: getTotalRow(rowData) { const initial = { fname: undefined, lname: undefined, position: undefined, office: 'Total', //

如何在ag表格的页脚显示特定列的总和。 例如,如果我在ag grid表格中有列名称salary,那么我想在网格底部显示工资总额,如下图所示。

您可以使用AgGrid文档部分中讨论的grid属性

使用问题中的列,您可以执行以下操作:

getTotalRow(rowData) {
  const initial = {
    fname: undefined,
    lname: undefined,
    position: undefined,
    office: 'Total', // if you want to display in the 'Total' in the Office column
    salary: 0,
  };

  // iterate overRow data summing each property for total
  // assuming lodash reduce is available and skipping actual summing logic of salary
  const rowTotal = reduce((totals, rowData) => {...}, initial) 


  // rowTotal has a structure like:
  //  {
  //    fname: undefined, // undefined should render blank cell in row at column
  //    lname: undefined,
  //    position: undefined,
  //    office: 
  //    salary: 1234567.89,
  //  }

  // have to format in an array as pinnedBottomRowData expects the same format as rowData
  return [rowTotal];
}
这种方法的缺点是,您必须手动运行列求和,并自己构建
rowData
对象,但我认为这是一个比列聚合简单得多的解决方案,如果您做的不仅仅是显示数据,那么列聚合很快就会变得复杂(进行单元格编辑,编辑后重新计算特定单元格等)

此外,这是固定在网格底部的,因此如果没有足够的行,那么最后一行数据和总行之间将有空间(请参见屏幕截图)。行/列标题不重要,因此我将它们涂掉


你检查过这个了吗?是的,我看到了,但是它的角度js解决方案,我需要普通js apiYes中的这个解决方案,agGrid没有一个友好的网格FooterRow选项,只是丑陋的pinnedBottomRowData实现,这真是太糟糕了。