2

我需要在某些条件下禁用/启用输入某些列,我可以用制表器来做吗?当我打开带有某种状态(布尔值或等)的表的页面时,可用或锁定输入的列。谢谢你。

例子:

//define some sample data
var tabledata = [
    {
        id: 1,
        name: "Oli Bob",
        age: "12",
        col: "red",
        dob: ""
    },
    {
        id: 2,
        name: "Mary May",
        age: "1",
        col: "blue",
        dob: "14/05/1982"
    },
    {
        id: 3,
        name: "Christine Lobowski",
        age: "42",
        col: "green",
        dob: "22/05/1982"
    },
    {
        id: 4,
        name: "Brendon Philips",
        age: "125",
        col: "orange",
        dob: "01/08/1980"
    },
    {
        id: 5,
        name: "Margret Marmajuke",
        age: "16",
        col: "yellow",
        dob: "31/01/1999"
    },
];

var table_3 = new Tabulator("#table_3", {
    height: 205,
    data: tabledata,
    layout: "fitColumns",
    columns: [
        {
            title: "Name",
            field: "name",
            width: 150,
            editor: "input"
        },
        {
            title: "Age",
            field: "age",
            align: "left",
            formatter: "progress",
            editor: "input"
        },
        {
            title: "Favourite Color",
            field: "col",
            editor: "input"
        },
        {
            title: "Date Of Birth",
            field: "dob",
            sorter: "date",
            align: "center",
        },
    ],
});

editor: "input"在某些情况下如何禁用?

4

1 回答 1

0

您可以将回调传递给列定义中的可编辑 选项,它将传递给正在编辑的单元格的单元格组件

然后您可以返回true以允许编辑或false拒绝编辑:

///define editor
var editCheck = function(cell){
    //cell - the cell component for the editable cell

    //get row data
    var data = cell.getRow().getData();

    return data.age > 18; // only allow the name cell to be edited if the age is over 18
}
//in your column definition for the column
{title:"Name", field:"name", editor:"input", editable:editCheck}

完整的详细信息可以在编辑文档中找到

于 2020-09-07T07:05:21.193 回答