Bob
Bob

Reputation: 1085

DataTables exclude hyperlinks from selecting rows

I'm using DataTables Select extension so I can select multiple rows. In this jsfiddle example it works, except for the fact that the rows are also selected when an hyperlink is clicked. I want hyperlinks excluded from selecting rows. How can I do this?

This is my DataTables Select initialization:

  $('#example').DataTable({
    select: {
      style: 'multi',
      selector: 'tr:not(a)'
    }
  });

Upvotes: 1

Views: 88

Answers (2)

davidkonrad
davidkonrad

Reputation: 85578

Simply prevent other listeners to be executed by stopImmediatePropagation() ;

$('a.do-nothing').on('click', function(e){
   e.stopImmediatePropagation();
});

updated fiddle -> https://jsfiddle.net/9hhaofky/2/

preventDefault() as you are using only prevent default behaviour, such as prevent checkbox from being checked.

Upvotes: 1

Rafael Munhoz
Rafael Munhoz

Reputation: 111

I think something like:

$('a.do-nothing').on('click', function(e){
    e.stopPropagation();
});

will do the trick ;)

PS.: I tested in the jsfiddle, so you can use another identifier to the a.do-nothing in your project.

Upvotes: 1

Related Questions