如何从制表符 table 中获取所有组
How to get all groups from tabulator table
我需要来自多级分组制表符 table 的 "group" 个对象数组,其中
组={字段:字符串,名称:字符串}
但是当我尝试解析 tabulator.getGroups() 的有效负载时,我遗漏了其中一个组。是否有用于从 table 中检索所有组的制表符 api 函数? tabulator.getGroups() 是我能在文档中找到的唯一函数。
https://codepen.io/awcastellano/pen/vMpydW
let data = [
{
"partType": "Disc Brake Pad",
"vehicle": "2019 chevy silverado",
"brand": "Cardone",
"partApplication": "Left Front/MKD794"
},
{
"partType": "Disc Brake Pad",
"vehicle": "2019 ford F150",
"brand": "STS",
"partApplication": "Left Front/MKD794"
},
{
"partType": "Disc Brake Rotor",
"vehicle": "2019 chevy silverado",
"brand": "Cardone",
"partApplication": "Left Front/MKD795"
},
{
"partType": "Disc Brake Pad",
"vehicle": "2019 chevy silverado",
"brand": "Cardone",
"partApplication": "Left Front/MKD795"
},
{
"partType": "Disc Brake Caliper",
"vehicle": "2019 chevy silverado",
"brand": "Cardone",
"partApplication": "Left Front/MKD796"
}
]
let columns = [{
title: "Part",
field: "partApplication"
}, ]
let table = new Tabulator('#tabulator', {
data: data,
columns: columns,
groupBy: ["vehicle", "partType", "brand"]
})
function groups() {
let groups = []
let groupComponents = table.getGroups()
if (groupComponents.length == 0) return groups
for (var i = 0; i < groupComponents.length; i++) {
groups.push({ field: groupComponents[i]._group.field, name: groupComponents[i]._group.key })
}
let groupList = groupComponents[0]._group.groupList
while (groupList.length != 0) {
for (var i = 0; i < groupList.length; i++) {
groups.push({ field: groupList[i].field, name: groupList[i].key })
}
groupList = groupList[0].groupList
}
return groups
}
在 codepen 控制台中调用 groups()。数组中缺少 { field: "brand", name: "STS" },但显示在 table 中。我试图将结果粘贴到此处,但无法弄清楚如何从 codepen 复制结果。
提前致谢!
检查控制台
https://codepen.io/dota2pro/pen/NmVzmv
const getAllGroups = function(input){
for(let i=0; i< input.length; i++){
console.log(allRows[i].getGroup());
// Use this or
console.log(allRows[i].getGroup()._group.key
,allRows[i].getGroup()._group.field);
// Use this
console.log('field: ', input[i]._row.modules.group.field,'key:',input[i]._row.modules.group.key );
}}
我需要来自多级分组制表符 table 的 "group" 个对象数组,其中
组={字段:字符串,名称:字符串}
但是当我尝试解析 tabulator.getGroups() 的有效负载时,我遗漏了其中一个组。是否有用于从 table 中检索所有组的制表符 api 函数? tabulator.getGroups() 是我能在文档中找到的唯一函数。
https://codepen.io/awcastellano/pen/vMpydW
let data = [
{
"partType": "Disc Brake Pad",
"vehicle": "2019 chevy silverado",
"brand": "Cardone",
"partApplication": "Left Front/MKD794"
},
{
"partType": "Disc Brake Pad",
"vehicle": "2019 ford F150",
"brand": "STS",
"partApplication": "Left Front/MKD794"
},
{
"partType": "Disc Brake Rotor",
"vehicle": "2019 chevy silverado",
"brand": "Cardone",
"partApplication": "Left Front/MKD795"
},
{
"partType": "Disc Brake Pad",
"vehicle": "2019 chevy silverado",
"brand": "Cardone",
"partApplication": "Left Front/MKD795"
},
{
"partType": "Disc Brake Caliper",
"vehicle": "2019 chevy silverado",
"brand": "Cardone",
"partApplication": "Left Front/MKD796"
}
]
let columns = [{
title: "Part",
field: "partApplication"
}, ]
let table = new Tabulator('#tabulator', {
data: data,
columns: columns,
groupBy: ["vehicle", "partType", "brand"]
})
function groups() {
let groups = []
let groupComponents = table.getGroups()
if (groupComponents.length == 0) return groups
for (var i = 0; i < groupComponents.length; i++) {
groups.push({ field: groupComponents[i]._group.field, name: groupComponents[i]._group.key })
}
let groupList = groupComponents[0]._group.groupList
while (groupList.length != 0) {
for (var i = 0; i < groupList.length; i++) {
groups.push({ field: groupList[i].field, name: groupList[i].key })
}
groupList = groupList[0].groupList
}
return groups
}
在 codepen 控制台中调用 groups()。数组中缺少 { field: "brand", name: "STS" },但显示在 table 中。我试图将结果粘贴到此处,但无法弄清楚如何从 codepen 复制结果。
提前致谢!
检查控制台
https://codepen.io/dota2pro/pen/NmVzmv
const getAllGroups = function(input){
for(let i=0; i< input.length; i++){
console.log(allRows[i].getGroup());
// Use this or
console.log(allRows[i].getGroup()._group.key
,allRows[i].getGroup()._group.field);
// Use this
console.log('field: ', input[i]._row.modules.group.field,'key:',input[i]._row.modules.group.key );
}}