简体   繁体   English

制表符:字段索引(多维数组)

[英]Tabulator :index of feild (MultiDimensional arrays)

I want to create tables by Tabulator.我想通过 Tabulator 创建表格。

my data is:我的数据是:

[{
    "trade_symbol": "aaa",
    "volume": 159842,
    "real": 0.051560379918588875,
    "date_time": "2020-07-06T09:34:51",
    "value": 0.12543630017452,
    "result": [{
            "title": ["R1"],
            "alias_title": ["R"],
            "value": 0.12543630017452,
            "value_type": 2
        }, {
            "title": ["RV"],
            "alias_title": ["B"],
            "value": true,
            "value_type": 4
        }
    ]
}, {
    "trade_symbol": "bbb",
    "volume": 144216,
    "real": 0.04997030626961907,
    "date_time": "2020-07-06T09:34:44",
    "value": 0.271246764452114,
    "result": [{
            "title": ["R1"],
            "alias_title": ["R"],
            "value": 0.271246764452114,
            "value_type": 2
        }, {
            "title": ["RV"],
            "alias_title": ["B"],
            "value": true,
            "value_type": 4
        }
    ]
}, {
    "trade_symbol": "ccc",
    "volume": 1566952,
    "real": 0.04988399071925754,
    "date_time": "2020-07-04T12:29:33",
    "value": 0.057654850019478,
    "result": [{
            "title": ["R1"],
            "alias_title": ["R"],
            "value": 0.057654850019478,
            "value_type": 2
        }, {
            "title": ["RV"],
            "alias_title": ["B"],
            "value": true,
            "value_type": 4
        }
    ]
}]

The "result" field may more than 1(this is a result of search for example we may have 1 or 5 result) Now I want to use "tabulator" ( http://tabulator.info/docs/4.7 ) “结果”字段可能超过 1(这是搜索结果,例如我们可能有 1 或 5 个结果)现在我想使用“制表符”( http://tabulator.info/docs/4.7

The number of "result" array element in all arrays is the same, but the number of it is not known.所有 arrays 中的“结果”数组元素的数量相同,但数量未知。

A column must be added to our table for each resualt.必须为每个结果在我们的表中添加一列。 Its value is in the value of Resualt item element.它的值在结果项元素的值中。 So we don't know the number of columns in this table.所以我们不知道这张表的列数。

But in Tabulator we must have only Flat data.但在制表器中,我们必须只有平面数据。

because "result" 's count is not fix,I can not use Flat Array.因为“结果”的计数不固定,我不能使用平面阵列。 (any result must be show in new Column) and I can not use this code: (任何结果都必须显示在新列中)并且我不能使用此代码:

table.addColumn({title:alldata[0].result.alias_title, field:alldata[0].result.value});

and Tabulator do not support index of array in field.和 Tabulator 不支持字段中数组的索引。

How can I create table with this data?如何使用这些数据创建表?

Here is an example from examples :这是示例中的示例

http://tabulator.info/examples/4.7#nested-tables http://tabulator.info/examples/4.7#nested-tables

var nestedData = [
    {id:1, make:"Ford", model:"focus", reg:"P232 NJP", color:"white", serviceHistory:[
       {date:"01/02/2016", engineer:"Steve Boberson", actions:"Changed oli filter"},
       {date:"07/02/2017", engineer:"Martin Stevenson", actions:"Break light broken"},
    ]},
    {id:1, make:"BMW", model:"m3", reg:"W342 SEF", color:"red", serviceHistory:[
       {date:"22/05/2017", engineer:"Jimmy Brown", actions:"Aligned wheels"},
       {date:"11/02/2018", engineer:"Lotty Ferberson", actions:"Changed Oil"},
       {date:"04/04/2018", engineer:"Franco Martinez", actions:"Fixed Tracking"},
    ]},
]

//define table
var table = new Tabulator("#example-table", {
    height:"311px",
    layout:"fitColumns",
    resizableColumns:false,
    data:nestedData,
    columns:[
        {title:"Make", field:"make"},
        {title:"Model", field:"model"},
        {title:"Registration", field:"reg"},
        {title:"Color", field:"color"},
    ],
    rowFormatter:function(row){
        //create and style holder elements
       var holderEl = document.createElement("div");
       var tableEl = document.createElement("div");

       holderEl.style.boxSizing = "border-box";
       holderEl.style.padding = "10px 30px 10px 10px";
       holderEl.style.borderTop = "1px solid #333";
       holderEl.style.borderBotom = "1px solid #333";
       holderEl.style.background = "#ddd";

       tableEl.style.border = "1px solid #333";

       holderEl.appendChild(tableEl);

       row.getElement().appendChild(holderEl);

       var subTable = new Tabulator(tableEl, {
           layout:"fitColumns",
           data:row.getData().serviceHistory,
           columns:[
           {title:"Date", field:"date", sorter:"date"},
           {title:"Engineer", field:"engineer"},
           {title:"Action", field:"actions"},
           ]
       })
    },
});

The number of "Result" array element in all arrays is the same, but the number of it is not known.所有 arrays 中的“Result”数组元素的数量相同,但数量未知。 A column must be added to our table for each result.必须为每个结果在我们的表中添加一列。 Its value is in the value of Result item element.它的值在 Result item 元素的值中。 So we don't know the number of columns in this table.所以我们不知道这张表的列数。 It is Not "nested-tables " in Rows.它不是行中的“嵌套表”。 We need multi column.我们需要多列。

enter image description here在此处输入图像描述

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

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