Search code examples
javascriptjqueryslickgrid

How to recognize which of two buttons in one cell in Slickgrid was clicked


I have made my custom formatter which contain string with two buttons.

function myCustomFormatter(row, cell, value, columnDef, dataContext) {
         return '<button class="k-button k-button-icontext" style="height:20px">Edit</button> <button class="k-button k-button-icontext" id="btnCare" style="height:20px">Take care</button>';
}

All i want now is correct recognition which of them was clicked. I already tried subscribe onClick event on Slickgrid like this

grid.onClick.subscribe(function (e, args) {
        if (args.grid.getColumns()[args.cell].field == 'Action') {...}
}

Do you have any suggestions or clues?


Solution

  • The cleanest way I've found is to render an onclick event for the buttons. You may want to render a row id in there as well, so the edit function knows which row the button is on. This is one of mine:

    <div class="slick-edit-preclick" onclick="EditPanel.Edit(11)">
    

    The other approach is to give the buttons unique names (for each row as well) and programmatically bind an event to each, but that's pretty messy and a bit unnecessary.