【问题标题】:Tabulator add a new row and edit content制表符添加新行并编辑内容
【发布时间】:2021-08-16 12:05:04
【问题描述】:

我有以下制表器设置:

var table = new Tabulator("#data-table", {
            layout: "fitColumns", //fit columns to width of table
            columns: [ //Define Table Columns
                { title: "Name", field: "name", editor:"input" },
                { title: "IP", field: "ip" },
            ],
            index:"name"
        });

另外,我注册了一个插入新行的函数:

function insertRow(){
            table.addData([{
                name: "",
                ip: "",
            }], true).then(function(rows){
                if (rows.length == 0) return;
                rows[0].getCell("name").edit();
            })

        }

当我调用函数insertRow()时,它可以在表格中插入一个新行,但不能打开第一个单元格的编辑。
但是,以下代码有效:

if (rows.length == 0) return;
                setTimeout(function(){
                    rows[0].getCell("name").edit();
                }, 100);

在文档http://tabulator.info/docs/4.9/update

addData 方法返回一个promise,这可以用来运行任何 数据加载后必须运行的其他命令 桌子。通过在承诺中运行它们,您可以确保它们只运行 在表格加载数据之后。

所以,我们似乎不能在 Promise 中立即调用 rows[0].getCell("name").edit()
这是正确的吗?
我的代码有问题吗?

【问题讨论】:

    标签: javascript tabulator


    【解决方案1】:

    如果您只添加一行,请使用addRow 函数而不是addData 函数:

    table.addRow({name: "", ip: ""], true)
    .then(function(row){
       rows.getCell("name").edit();
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-19
      • 1970-01-01
      • 1970-01-01
      • 2022-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多