Search code examples
javascriptjquerybootstrap-table

How can I highlight a table row based on a cell click?


I have a Bootstrap Table. If the user clicks on a specific cell (Delete), I would like to highlight the row red. I am using the click-cell.bs.table, but nothing happens when I click on a cell.

$table.on("click-cell.bs.table", function (field, value, row, $element) {
   if (field == 'Delete') {
        $element.parent().toggleClass('bg_delete');
   }
});

http://jsfiddle.net/46eaytfn/


Solution

  • The function needs events as its first parameter.

    And two minor issues: 1) Correct $table to $('#table') and 2) Remove parent function.

    Here is the solution:

    $('#table').on("click-cell.bs.table", function (e, field, value, row, $element) {
    
    if (field === 'Delete') {
            $element.toggleClass('bg_delete');
       }
    });