Pipo
Pipo

Reputation: 5601

How disable sorting on click on column title but allow for click on arrow in jQuery datatable?

I am rendering a table thanks to jQuery datatable plugin .

When you allow sorting on a column , column is sorted if you click on title text or on arrow just near:

enter image description here

Do you know how to disable sorting for click on text but let sorting for click on arrows?

Upvotes: 3

Views: 2641

Answers (2)

burgund
burgund

Reputation: 165

I had the same problem and I solve it this way (found the solution here: https://datatables.net/forums/discussion/27035/how-to-disable-sorting-click-event-on-table-header-children):

If you supose the checkbox has the ID #chkbx, this code should work:

$('#chkbx').click(function(event){

  //Your code here

  event.stopPropagation();
});

With the event.stopPropagation() prevent the sorting of the column.

Upvotes: 6

jonmrich
jonmrich

Reputation: 4323

$('#example').dataTable( {
      "aoColumnDefs": [
          { 'bSortable': false, 'aTargets': [ 1 ] }
       ]
});

1 is your column number (remember the first column is actually 0).

Upvotes: -1

Related Questions