user2242044
user2242044

Reputation: 9243

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/

Upvotes: 0

Views: 958

Answers (2)

VvV
VvV

Reputation: 1588

You need to change a little bit of CSS. Please have a look.

see sample code below http://jsfiddle.net/4ek2znw3/

#table .bg_delete td {
   background-color: #ff0000 !important;
   opacity: 0.5  !important;
}

Upvotes: 1

T.Liu
T.Liu

Reputation: 512

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');
   }
});

Upvotes: 2

Related Questions