Hari kanna
Hari kanna

Reputation: 2521

Data table multiple row selection

How to change background color of row when I click the checkbox?

Upvotes: 2

Views: 1636

Answers (1)

BalusC
BalusC

Reputation: 1108632

You need a shot of Javascript for this.

<h:selectBooleanCheckbox onclick="highlightRow(this)">

with

function highlightRow(checkbox) {
    getParentByTagName(checkbox, 'tr').style.background = (checkbox.checked) ? '#6f6' : 'none';
}
function getParentByTagName(element, tagName) {
    var p = element.parentNode;
    return p ? ((p.tagName.toLowerCase() == tagName.toLowerCase()) ? p : getParentByTagName(p, tagName)) : false;
}

Or if you're already using jQuery:

function highlightRow(checkbox) {
    $(checkbox).closest('tr').css('background', checkbox.checked ? '#6f6' : 'none');
}

Upvotes: 2

Related Questions