如何在不添加 columns 属性的情况下在 Tabulator 中创建 table?
How do I create a table in Tabulator without having to add the columns attribute?
文档中给出的代码需要列属性和相应的 JSON 列映射。但是我有一个包含 100 多列的数据集,我不想手动映射它们。制表符中是否有一个函数可以使用 JSON 中给出的原始列名创建 table。我尝试了 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"},
],
});
不是函数,而是 table 构造函数 属性:
http://tabulator.info/docs/4.3/columns#autocolumns
文档中给出的代码需要列属性和相应的 JSON 列映射。但是我有一个包含 100 多列的数据集,我不想手动映射它们。制表符中是否有一个函数可以使用 JSON 中给出的原始列名创建 table。我尝试了 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"},
],
});
不是函数,而是 table 构造函数 属性: http://tabulator.info/docs/4.3/columns#autocolumns