一次编辑多行/使用 Tabulator.js 批量编辑

Editing multiple lines at once / bulk editing with Tabulator.js

我正在使用 tabulator.js 以 table 的形式显示和操作数据。如何使用制表符一次编辑多行数据?例如,如果我有 table 个项目,列名称和价格,我想将多个条目的价格更改为相同的值。

目标是标记我要编辑和键入的字段或 select 新值,应该为所有 selected 条目更改。我在文档的编辑部分没有找到任何关于多行编辑/批量编辑的信息。这可以通过任何方式实现吗?

没有内置的方法来实现这一点。

您可以使用 getRows 函数获取所有 table 行,然后迭代每一行,调用行组件上的 update 函数来更新行数据。

var rows = table.getRows();

rows.forEach((row)=>{
    row.update("name":"steve"); //update the name of each row to steve;
});

这有一点缺点,因为它会在每次更新行时触发 table 的更新。

为了解决这个问题并提高效率,您可以在更新之前调用 blockRedraw,然后在更新之后调用 restoreRedraw 函数,这样 table 只会重绘一次。

var rows = table.getRows();

table.blockRedraw();

rows.forEach((row)=>{
    row.update("name":"steve"); //update the name of each row to steve;
});

table.restoreRedraw();