跳至主要内容

getTable()

描述

获取对 Pivot 表格中底层 Table widget 实例的访问权限

此方法用于访问 Pivot 中底层的 Table widget 实例。它提供对 Table 功能的直接访问,支持数据序列化和以各种格式导出等操作。Table API 拥有自己的 api.exec() 方法,可以调用 open-rowclose-rowexportfilter-rows 事件。

用法

getTable(wait:boolean): Table | Promise;

参数

wait - 定义是否等待 Table API 在 Pivot 中就绪(当 Table API 在 Pivot 初始化期间使用时为必需)。如果值设置为 true,该方法将返回一个包含 Table API 的 promise。

示例

在下面的示例中,我们通过 api.exec() 方法获取 Table widget API 的访问权限,并在点击按钮时触发 Table 的 export 事件。

// 创建 Pivot
const table = new pivot.Pivot("#root", {
fields,
data,
config: {
rows: ["studio", "genre"],
columns: [],
values: [
{
field: "title",
method: "count"
},
{
field: "score",
method: "max"
}
]
}
});

// 访问 table 实例
let table_instance = table.getTable();

function toCSV() {
table_instance.exec("export", {
options: {
format: "csv",
cols: ";"
}
});
}

const exportButton = document.createElement("button");

exportButton.addEventListener("click", toCSV);
exportButton.textContent = "Export";

document.body.appendChild(exportButton);

相关文章