如何从制表符表中获取所有组

时间:2019-04-16 14:20:20

标签: tabulator

我需要一个来自多级分组制表器表的“组”对象数组,其中

group = {字段:字符串,名称:字符串}

但是当我尝试解析tabulator.getGroups()的有效负载时,我缺少其中一个组。是否有一个制表器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()。 {字段:“品牌”,名称:“ STS”}}缺少数组,但仍显示在表中。我试图将结果粘贴到此处,但无法弄清楚如何从Codepen复制结果。

谢谢!

1 个答案:

答案 0 :(得分:0)

检查控制台

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 );

    }}