Search code examples
javascripthtmlbuttononclicktabulator

How to pass a variable into the onclick method in a html element


Im currently using the tabulator library to create tables based on json data. I am trying to use a custom cell formatter to add a button into a cell.

Here is my method:

var graphButton = function(cell, formatterParams, onRendered){
   var button = '<button   onclick="customMethod(cell.getRow().getData())">myLabel</button>';
   return button;
};

I then pass graphButton into the table's definition.

The button is displayed correctly. However, when I click the button, I get an error stating: can't find variable: cell.

How do I correctly pass the cell variable into customMethod?


Solution

  • try to use this way not sure but as per standards this will be work

    var graphButton = function(cell, formatterParams, onRendered) {
       var button = `<button onclick="customMethod('${cell.getRow().getData()}')">myLabel</button>`;
       return button;
    };