使用 + 键在 Tabulator 中添加新行

use the + key to add new row in Tabulator

我正在尝试使用键盘向制表符添加新行,所以我按照以下步骤操作 创建了如下扩展部分

Tabulator.prototype.extendModule("keybindings", "actions", {
    "addNewRow":function(){ //delete selected rows

         var id = Math.floor((Math.random() * 10000) + 1) * -1;
         Tabulator.addRow({ iD: id });

    },
});

但是我发现要添加新行我需要引用制表符对象才能这样做,我需要它对整个站点中的所有制表符都是通用的,所以我不想引用制表符对象每次 运行 ti 现在我必须像下面那样

 Tabulator.prototype.extendModule("keybindings", "actions", {
        "addNewRow":function(){ //delete selected rows

             var id = Math.floor((Math.random() * 10000) + 1) * -1;
             tblgridPage1.addRow({ iD: id });

        },
    });

您可以使用模块执行的范围来执行此操作,因此您的代码应如下所示:

Tabulator.prototype.extendModule("keybindings", "actions", {
    "addNewRow":function(){
         var id = Math.floor((Math.random() * 10000) + 1) * -1;
         this.table.addRow({ iD: id });
    },
});

this.table 使您可以访问正在执行函数的 table