如何在Tabulator中创建表而无需添加columns属性?

时间:2019-08-09 16:22:49

标签: tabulator

文档中给出的代码需要column属性和相应的JSON列映射。但是我有一个包含100多个列的数据集,我不想手动映射它们。制表器中是否有一个函数可以使用JSON中给定的原始列名创建表。我尝试了SetData函数,但是它不起作用。我试图从下面的代码中删除columns属性,但是它仍然不起作用(表未在网络中显示)。

文档中给出的代码不起作用:

    var table = new Tabulator("#example-table", {
        index:"age", //set the index field to the "age" field.
    });

var tableData = [
    {id:1, name:"Billy Bob", age:"12", gender:"male", height:1, col:"red", dob:"", cheese:1},
    {id:2, name:"Mary May", age:"1", gender:"female", height:2, col:"blue", dob:"14/05/1982", cheese:true},
]

table.setData(tableData);

代码仅适用于列属性:

var table = new Tabulator("#example-table", {
    index:"age", //set the index field to the "age" field.
});

var tableData = [
    {id:1, name:"Billy Bob", age:"12", gender:"male", height:1, col:"red", dob:"", cheese:1},
    {id:2, name:"Mary May", age:"1", gender:"female", height:2, col:"blue", dob:"14/05/1982", cheese:true},
]

var table = new Tabulator("#example-table", {
    data:tableData, //set initial table data
    columns:[
        {title:"Name", field:"name"},
        {title:"Age", field:"age"},
        {title:"Gender", field:"gender"},
        {title:"Height", field:"height"},
        {title:"Favourite Color", field:"col"},
        {title:"Date Of Birth", field:"dob"},
        {title:"Cheese Preference", field:"cheese"},
    ],
});

1 个答案:

答案 0 :(得分:0)

不是函数,而是表的构造函数属性: http://tabulator.info/docs/4.3/columns#autocolumns