Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery dataTable change row color

I am using JQuery datatable,
I need to change the color of the row on the mouse over event (the highligthed row)
I tried:

table.display tr.even.row_selected td {
    background-color: red;
}

table.display tr.odd.row_selected td {
    background-color: blue;
}

JSFiddle

like image 740
Nk SP Avatar asked Sep 09 '14 10:09

Nk SP


3 Answers

Try this CSS:

table.display tbody tr:nth-child(even):hover td{
    background-color: red !important;
}

table.display tbody tr:nth-child(odd):hover td {
    background-color: blue !important;
}

UPDATED jsFIDDLE DEMO

like image 189
reuelab Avatar answered Sep 21 '22 11:09

reuelab


One of the JS snippets I write at the start of each project is to add some basic formatting to tables. Include this inside your $(function() { ... }); block

    $('table tr').mouseover(function() {
        $(this).addClass('row_selected');
    });
    $('table tr').mouseout(function() {
        $(this).removeClass('row_selected');
    });

Similarly, this bit will take away the hassle of adding odd/even markup to every row in the table, as your are building it

$('table').each(function() { $(this).find('tr:even').addClass('even'); });
$('table').each(function() { $(this).find('tr:odd').addClass('odd'); });
like image 38
LS11 Avatar answered Sep 19 '22 11:09

LS11


This?

table.display tbody .odd:hover {
    background-color: red !important;
}
table.display tbody .even:hover {
    background-color: blue !important;
}
like image 31
Roi Avatar answered Sep 22 '22 11:09

Roi