Search code examples
tabulator

use the + key to add new row in Tabulator


am trying to add new row to tabulator using the key board ,so i followed the given below steps Created an extended part as below

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

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

    },
});

hut i found that to add new row i need to refer to the tabulator object to do so , i need this to be generic to all my tabulators in the whole site ,so i do not want to refer to tabulator object every time to run ti now i must have it like below

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

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

        },
    });

Solution

  • You can use the scope that the module is executed in to do this, so your code should look like this:

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

    the this.table gives you access to the table that the function is being executed on