【问题标题】:How do I create a table in Tabulator without having to add the columns attribute?如何在制表符中创建表格而无需添加列属性?
【发布时间】:2019-08-09 16:22:49
【问题描述】:

文档中给出的代码需要 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);

仅使用 Column 属性的代码:

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"},
    ],
});

【问题讨论】:

    标签: tabulator


    【解决方案1】:

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

    【讨论】:

    • 非常感谢。
    猜你喜欢
    • 1970-01-01
    • 2014-05-31
    • 2011-08-20
    • 2014-09-02
    • 2016-01-13
    • 2018-10-10
    • 2016-01-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多