簡體   English   中英

getData不反映對Tabulator表所做的更改

[英]getData does not reflect changes made on the Tabulator table

我是JavaScript和Tabulator的新手,我被困在這個地方,感謝您的幫助。

我已經在tabulator表上加載了數據並對其進行了一些更改(添加新列,刪除列等),這些更改反映在表中,但是當我使用table.getData()時,未反映更新的數據(舊數據)體現)。 我需要這個來使用其他一些地方。 我哪里錯了?

這是示例代碼。

tabulatorTable = new Tabulator("#dfTable", {
selectable:true,
data:dataJson,
layout:"fitColumns",      //fit columns to width of table
responsiveLayout:"hide",  //hide columns that dont fit on the table
tooltips:true,            //show tool tips on cells
addRowPos:"top",          //when adding a new row, add it to the top of 
//table
history:true,             //allow undo and redo actions on the table
pagination:"local",       //paginate the data
paginationSize:20,         
movableColumns:true,      //allow column order to be changed
resizableRows:true,       //allow row order to be changed

columns:[
        {title:"YearsExperience", field:"YearsExperience", editor:"number"},
        {title:"Salary", field:"Salary", sorter:"number"}
        ]

});

tabulatorTable.addColumn({formatter:"rownum", title:"id"}); **// Adding new column to the table**
console.log(tabulatorTable.getData()); **// Does not reflect the newly added column**

預期的Json文件包含添加的列數據(標題 - “id”)

您只能通過向網格添加列來修改數據。 此外,您添加的列是“rownum”格式化程序,並且未綁定到字段,因此要添加的密鑰是什么? 您需要顯式修改表中的數據。

見這里: http//tabulator.info/docs/4.2/update

解決了它看到片段

tabulatorTable.addColumn({
  formatter: "rownum",
  field: "id",
  title: "id"
});

 const dataJson = [{ 'YearsExperience': 2, 'Salary': 40000 }, { 'YearsExperience': 3, 'Salary': 50000 }, ] const tabulatorTable = new Tabulator("#dfTable", { selectable: true, data: dataJson, layout: "fitColumns", //fit columns to width of table responsiveLayout: "hide", //hide columns that dont fit on the table tooltips: true, //show tool tips on cells addRowPos: "top", //when adding a new row, add it to the top of //table history: true, //allow undo and redo actions on the table pagination: "local", //paginate the data paginationSize: 20, movableColumns: true, //allow column order to be changed resizableRows: true, //allow row order to be changed columns: [{ title: "YearsExperience", field: "YearsExperience", editor: "number" }, { title: "Salary", field: "Salary", sorter: "number" } ] }); tabulatorTable.addColumn({ formatter: "rownum", field: "id", title: "id" }); // Adding new column to the table** console.log(tabulatorTable.getData()); // Does not reflect the newly added column** 
 <link href="https://cdnjs.cloudflare.com/ajax/libs/tabulator/4.2.7/css/tabulator.min.css" rel="stylesheet" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/tabulator/4.2.7/js/tabulator.min.js"></script> <div id="dfTable"></div> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM