【发布时间】: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