简体   繁体   中英

row selection on row click but not on hyperlink click in one of the column in jquery datatable?

i have my customer dataTable which has five columns. one column contains hyperlink. One of the column is checkbox. i want when user clicks on the row, that row should be selected(which means row color should change and checkbox should be selected). i can do it with below code snippet

 $("#customer").on('click', $.fn.getDataTablesClickHandler("#selectAll"));
 //where customer is the html div associated with dataTable and call the same function which gets triggered
 //on call of selectAll html element. Inside that function i toggle the class of row

It works great. But my problem is i dont want this to happen(ie row seection) on click of link inside one of the column. how i can do this?So basically how can i restrict firing getDataTablesClickHandler on click of certain link in a cell or
on click on cell?

Try this out, you want to check out which target is being clicked, and ignore it if it's an anchor tag.

$("#customer").on('click', function(event) {
    if(event.target.tagName == 'A')
        return;

    $.fn.getDataTablesClickHandler("#selectAll").apply(this);
});

You could do something like this:

if customer is your table;

 $("#customer").on('click', 'tr', function(){
    if( !$(this).is('tr') )
        return;
    $.fn.getDataTablesClickHandler("#selectAll");
 });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM