javascript - 如何根据 Tabulator 中的选定选项卡设置列
问题描述
我有几个选项卡,其中每个选项卡都有数据表。我正在尝试使用制表符并基于活动选项卡我正在尝试设置列。
我使用setColumns
了方法,但出现错误:
Cannot read property 'forEach' of undefined
请在jsfiddle
其中找到我的代码的链接:
var table = new Tabulator("#example-table", {
layout: "fitColumns",
//data : tabledata,
autoColumns: true,
});
if (this.activeTabName == "Role Card") {
let columns: [{
title: "Name",
field: "name",
sorter: "string",
width: 200
},
{
title: "Progress",
field: "progress",
sorter: "number",
formatter: "progress"
},
{
title: "Gender",
field: "gender",
sorter: "string"
},
{
title: "Rating",
field: "rating",
formatter: "star",
align: "center",
width: 100
},
{
title: "Favourite Color",
field: "col",
sorter: "string"
},
]
table.setColumns(columns)
}
https://jsfiddle.net/qc9r8t4p/
请帮助我实现这一目标。
解决方案
您的代码中存在错误,导致将列变量传递给 setColumns 函数时未定义
您将值分配给变量的位置
let columns: [{
你有一个冒号而不是等号,它应该是:
let columns = [{
推荐阅读
- node.js - Mongoose - 在包含 ObjectID 数组的字段中查找字符串数组
- arrays - How to change cell based on another cell value on Google Sheets
- python - 从文件生成 Python 列表,并从源匹配返回特定值
- sql - T-SQL 插入列名作为第一行
- android - 我仍然不明白为什么会出现错误:有意图
- git - 复制 git repo 并更改远程 - 怎么称呼这个?
- postgresql - 在 psql 中运行和引用函数一次
- typescript - 异步承诺尝试捕获等待返回混乱
- node.js - 有没有办法控制我的对话流机器人听用户的时间?
- tableau-api - 为什么在 Tableau 中日期是 Dimension 而不是 Measure?