greencucumber
greencucumber

Reputation: 29

Datatables - highlight row on mouseover

I try to highlight a row when a certain value is error but instead it highlights every row on mouseover.

Where is my mistake?

https://jsfiddle.net/p0np06mx/

$('#table1').DataTable( {
        "bFilter" : false,
        "ordering": true,
        columnDefs: [{
        orderable: false,
        targets: "no-sort"}],
        "paging": false,
        drawCallback: function (settings) {
        $('#table1 tr').each(function () {
            var Cell = $(this).find('td:eq(3)');
            debugger;
            if (Cell.text() !== 'error') {

                $(this).find('button').hide();
                $(this).find('textarea').hide();

            }else{

                $(this).parent().on('mouseover', 'tr', function() {
                    $(this).css('background-color', '#ff6900'); 

                    $(this).bind("mouseout", function(){
                        $(this).css('background-color', '');
                    });

                });
            }

        });
    }

Upvotes: 0

Views: 3749

Answers (2)

Renzo Calla
Renzo Calla

Reputation: 7706

fiddle ,just replace

$(this)

with

cell

you make sure you are pointing to the right element

Upvotes: 2

Viktor
Viktor

Reputation: 101

You should run the query on mouseover. Now, you run the cell queries right after drawing your table.

Upvotes: 0

Related Questions