在制表器表的每个嵌套数据树下添加总和

时间:2019-07-24 10:16:17

标签: tabulator

我正在尝试为嵌套表实现列总和。 文档将其显示在一个简单的表here中。 但是,它不适用于嵌套表。

我尝试在列定义中包含bottomCalc:"sum"

columns: [
{ title: "New Lead", field: "newLeadCount", width: 150, bottomCalc: "sum" },
],

我想获得每个主要行组或发布ID的总和。但目前,它在底部显示总和。而且由于方法不正确,它也无法计数。 我尝试了这个: enter image description here

1 个答案:

答案 0 :(得分:0)

这可以通过使用自定义计算器功能汇总子值来完成,需要注意的是将字段作为参数传递。

这段代码只是说明了https://jsfiddle.net/amwrfzt8/所需的方法

这是html

<div id="example-table"></div>

这在脚本中。

var tableDataNested = [
  {group:"Backend Engineer A", name:"Sourced", applied:300, screened:40, interviewed:5},
  {group:"Backend Engineer A", name:"Referred", applied:3, screened:1, interviewed:0},
  {group:"Backend Engineer A", name:"University", applied:4, screened:2, interviewed:1},
  {group:"Backend Engineer B", name:"Sourced", applied:1000, screened:140, interviewed:55},
  {group:"Backend Engineer B", name:"Referred", applied:30, screened:11, interviewed:2},
  {group:"Backend Engineer B", name:"University", applied:40, screened:22, interviewed:10},
];

var table = new Tabulator("#example-table", {
    data:tableDataNested,
    dataTree:true,
    dataTreeStartExpanded:true,
    groupBy: "group",
    columns:[
      {title:"Name", field:"name", responsive:0},
      {title:"Applied", field:"applied", bottomCalc: "sum"},
      {title:"Screened", field:"screened", bottomCalc: "sum"},
      {title:"Interviewed", field:"interviewed", bottomCalc: "sum"},
    ],
});

有关完整的讨论,请访问https://github.com/olifolkerd/tabulator/issues/2235