0

Am using jQuery Datatables for listing of the users, and using the selectable property to select and unselect rows. Now I have a issue that I want to make one row non clickable (i.e. the row of logged in user)... how can I do that ..Any help will be appreciated

$('#example tr').click( function() { 

}

How can I disable this function for a particular row?

Brian Tompsett - 汤莱恩
  • 5,195
  • 62
  • 50
  • 120
Shanib
  • 155
  • 3
  • 13

3 Answers3

0

Something like this? (add class="trDisable" to the row that shall have no click function)

$('#example tr').not("#example tr.trDisable").click( function()

or

$('#example tr.trDisable').click( function(e) {
    e.stopPropagation()
}
madth3
  • 7,001
  • 11
  • 45
  • 69
BjarkeCK
  • 5,315
  • 5
  • 38
  • 57
0

two ways come to my mind

1 each() usage

$('#example tr').each(function(i) {
    if ( i === 2 ) {//this will select third tr
      $(this).off();
    }
});

2 eq() usage //im not really sure this works on tables, maybe index() will

var disabledRow = $('#example tr').eq(2);//this will deactive third row
if ( contition ) {
  disabledRow.off();
}

and you can read these questions, they should help

jquery disable click until animation is fully complete

how to define condition with clicked objet's parent?

Community
  • 1
  • 1
Barlas Apaydin
  • 6,794
  • 10
  • 50
  • 81
0

I know this is an old thread but might help someone..

        $('#example').on('click', 'tbody tr', function () {
            var table = $('#example').DataTable();

            // Check if any rows are selected
            if (table.row(this, { selected: true }).any()) {
                // if condition here, if not valid
                if (!condition) table.row(this).deselect();
            }
        });