Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datatables - Only allow sorting with buttons

Is there a way of disabling the column sorting in datatables when clicking on the column header and only allow sorting with the sorting icons (check the red arrow in the picture below)?

enter image description here

My reason for wanting to disable the sorting is that I am using the headers for column filtering and when you click on the header to enter a string the table sorts by that column (I know it's ugly, but I will change the input box design later).

enter image description here

I checked their options and could not find anything. I also checked the source code but that was way way way way beyond my knowledge level.

Thanks for any help/suggestion!

/Patrik

like image 932
PatrikJ Avatar asked Feb 10 '23 11:02

PatrikJ


1 Answers

SOLUTION

Add click event handler for each input in the header and stop event propagation to the DataTables plug-in.

$('.filter').on('click', function(e){
   e.stopPropagation();    
});

DEMO

See this jsFiddle for code and demonstration.

like image 57
Gyrocode.com Avatar answered Feb 12 '23 00:02

Gyrocode.com