【问题标题】:How to set columns based on selected tab in Tabulator如何根据 Tabulator 中的选定选项卡设置列
【发布时间】:2020-02-05 07:28:04
【问题描述】:

我有几个标签,其中每个标签都有数据表。 我正在尝试使用制表符并基于活动选项卡我正在尝试设置列。

我使用了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/

请帮助我实现这一目标。

【问题讨论】:

    标签: javascript angular datatables tabulator


    【解决方案1】:

    您的代码中存在错误,导致当您将 columns 变量传递给 setColumns 函数时未定义该变量

    将值分配给变量的位置

     let columns: [{
    

    你有一个冒号而不是一个等号,它应该是:

     let columns = [{
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-18
      • 2011-10-17
      • 1970-01-01
      • 1970-01-01
      • 2017-07-27
      • 2012-10-28
      • 2018-06-23
      • 2018-01-16
      相关资源
      最近更新 更多