简体   繁体   English

如何在 ag-grid 的页脚中显示特定的列总和

[英]How display particular column summation in footer in ag-grid

在此处输入图像描述 How to Display total sum of particular column at in footer of ag-grid table.如何在 ag-grid 表的页脚中显示特定列的总和。 for example if i have column name salary in ag-grid table then i want to show total salary sum at the bottom of grid as display in following screen.例如,如果我在 ag-grid 表中有列名工资,那么我想在网格底部显示总工资总和,如下面的屏幕所示。

You could use the pinnedBottomRowData grid property that is talked about in the Row Pinning section of AgGrid's documentation.您可以使用在 AgGrid 文档的行固定部分中讨论的pinnedBottomRowData网格属性。

Using the columns from the question you could do something like the following:使用问题中的列,您可以执行以下操作:

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];
}

The downside of this approach is that you have to run the column summations manually and build the rowData object yourself but I think this is a much more trivial solution than column aggregations which get complex pretty quick if you are doing more than displaying data (making cell edits, recalculating specific cells after edits, etc.)这种方法的缺点是您必须手动运行列求和并自己构建rowData object 但我认为这是一个比列聚合更简单的解决方案,如果您要做的不仅仅是显示数据(使单元格编辑,编辑后重新计算特定单元格等)

Also this is pinned to the bottom of the grid, so if you don't have enough rows you will have space between the last row of data and the Total row (see screenshot).这也固定在网格的底部,因此如果您没有足够的行,您将在最后一行数据和 Total 行之间留出空间(参见屏幕截图)。 Row/Column headers don't matter so I blacked them out.行/列标题无关紧要,所以我将它们涂黑了。

最后一行和固定底行之间的空间

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM