我正在尝试为嵌套表实现列总和。 文档将其显示在一个简单的表here中。 但是,它不适用于嵌套表。
我尝试在列定义中包含bottomCalc:"sum"
。
columns: [
{ title: "New Lead", field: "newLeadCount", width: 150, bottomCalc: "sum" },
],
答案 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