有没有办法在不重新创建制表符的情况下打开/关闭行可选选项

时间:2019-10-28 18:46:28

标签: tabulator

标题几乎可以说明这一点,我有可以选择不同角色的用户,我需要根据他们选择的角色来打开/关闭行选择功能,这是否可能,或者您是否必须重新创建制表符更改此值?

2 个答案:

答案 0 :(得分:0)

在这种情况下,我只能选择名称为Oli Bob的行,请参见Documentation

根据您的意愿使用

selectableCheck:function(row){
    //row - row component
    return row.getData().age > 18; //allow selection of rows where the age is greater than 18
},

const tabledata = [{
    name: "Oli Bob",
    location: "United Kingdom",
    gender: "male",
    col: "red",
    dob: "14/04/1984"
  },
  {
    name: "Oli Bob",
    location: "United Kingdom",
    gender: "male",
    col: "red",
    dob: "14/04/1984"
  },
  {
    name: "Jamie Newhart",
    location: "India",
    gender: "male",
    col: "green",
    dob: "14/05/1985"
  }
];

let selectable = false;
const table = new Tabulator("#example-table", {
  data: tabledata,
  selectable: true,
  selectableCheck: function(row) {
    const name = row.getData().name;
    return name === "Oli Bob";
  },
  columns: [{
      title: "Row Num",
      formatter: "rownum"
    },
    {
      title: "Name",
      field: "name",
      width: 200
    },
  ],
});
<script src="https://unpkg.com/tabulator-tables@4.4.3/dist/js/tabulator.min.js"></script>
<link href="https://unpkg.com/tabulator-tables@4.4.3/dist/css/tabulator.min.css" rel="stylesheet" />
<div id="example-table"></div>

答案 1 :(得分:0)

实例化表后,此选项不可切换,但是您可以使用Selection Eligibility函数来确定当前是否应选择该行:

var table = new Tabulator("#example-table", {
    selectableCheck:function(row){
        //row - row component
        return row.getData().age > 18; //allow selection of rows where the age is greater than 18
    },
});

您可以对上面的示例进行调整,以查看您可以切换以确定表是否可选的全局布尔值