4

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

2
  • Not sure of the datatables way, but you can cancel the default click action from propagating to the table header from the input. Commented Jul 28, 2015 at 13:26
  • add an onclick even on the selectors Commented Jul 28, 2015 at 15:00

1 Answer 1

8

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Hi! Thanks for your help! It still sorts when I click the column header AND when I click the sort icons though.
AH, now I see. Just need to expand the filter. Let me try in my application.
You sir, are a genious! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.