gpt4 book ai didi

tabulator - 如何重新加载制表数据表中的数据?

转载 作者:行者123 更新时间:2023-12-01 15:02:25 26 4
gpt4 key购买 nike

我正在尝试使用 tabulator 加载动态数据我可以使用以下代码生成表格和数据:

 $("#example-table").tabulator({
layout:"fitColumns",

columns:[ //Define Table Columns
{title:"Name", field:"name", width:150},
{title:"Age", field:"age", align:"left", formatter:"progress"},
{title:"Favourite Color", field:"col"},
{title:"Date Of Birth", field:"dob", sorter:"date", align:"center"},
],
});
var tabledata = [
{id:1, name:"Oli Bob", age:"12", col:"red", dob:""},
{id:2, name:"Mary May", age:"1", col:"blue", dob:"14/05/1982"},
{id:3, name:"Christine Lobowski", age:"42", col:"green", dob:"22/05/1982"},
{id:4, name:"Brendon Philips", age:"125", col:"orange", dob:"01/08/1980"},
{id:5, name:"Margret Marmajuke", age:"16", col:"yellow", dob:"31/01/1999"},
];

// $("#example-table").tabulator("setData", []);

$("#example-table").tabulator("setData", tabledata);

但是,当我尝试重新加载相同的数据 onclick 函数时,出现错误:
 Options Error - Tabulator does not allow options to be set after initialization unless there is a function defined for that purpose

所以我的问题是如何清空表的数据并重新加载新数据或相同数据

最佳答案

对此的公认答案有点矫枉过正,您可以调用 设置数据 setColumns 创建表后的任何函数。没有必要先摧毁它

//update columns and data without destroying the table
$("#example-table").tabulator("setColumns", res["column"]);
$("#example-table").tabulator("setData", res["data"]);

关于tabulator - 如何重新加载制表数据表中的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51336415/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com